问题描述
我通过 OHAttributeLabel
和成功添加了
换句话说,正确的范围加下划线并且看起来像一个链接。 UILabel
的链接 - (void) addCustomLink:(NSURL *)linkUrl inRange:(NSRange)range;
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.
但是,我无法点击/触摸链接。还有什么必须在文本范围内的 addCustomLink
方法吗? FWIW,即使大部分 OHAttributedLabel
代码引用了 IBOutlet
,我也没有使用Interface Builder。
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
.
推荐答案
在这种情况下所需的代码只是:
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];
非常感谢!
这篇关于如何在OHAttributedLabel中使CustomLink可触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!