如何在OHAttributedLabel中使CustomLink可触摸

时间:2012-04-12 03:00:12

标签: ios uilabel

我已成功通过UILabelOHAttributeLabel-(void)addCustomLink:(NSURL*)linkUrl inRange:(NSRange)range;添加链接。换句话说,正确的范围带有下划线,看起来像一个链接。

但是,我无法点击/触摸链接。在文本范围内有addCustomLink方法还有什么必须做的吗? FWIW,即使很多OHAttributedLabel代码都引用了IBOutlet,我也没有使用Interface Builder。

1 个答案:

答案 0 :(得分:6)

在这种情况下所需的代码只是:

[myLabel setDelegate:self];

在感兴趣的人的背景下:

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

非常感谢!

相关问题