How to make CustomLink touchable in OHAttributedLabel

大憨熊 提交于 2019-12-21 17:42:46

问题


I am successfully adding links to a UILabel via OHAttributeLabel and -(void)addCustomLink:(NSURL*)linkUrl inRange:(NSRange)range; In other words, the correct range is underlined and looks like a link.

However, I cannot click/touch on the link. Is there anything else that must be done that the addCustomLink method on the range of text? FWIW, I am not using Interface Builder even though much of the OHAttributedLabel code makes references to IBOutlet.


回答1:


The required code in this case was simply:

[myLabel setDelegate:self];

And in context for those interested is:

descriptionLabel.attributedText = [NSMutableAttributedString attributedStringWithString:@"foo"];
[myLabel addCustomLink:[NSURL URLWithString:urlString] inRange:NSMakeRange(myLocation, myLength)];
[myLabel setDelegate:self];

Many thanks!



来源:https://stackoverflow.com/questions/10116820/how-to-make-customlink-touchable-in-ohattributedlabel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!