2012-04-12 41 views
4

我正在通过OHAttributeLabel-(void)addCustomLink:(NSURL*)linkUrl inRange:(NSRange)range;成功地将链接添加到UILabel换句话说,正确的范围带下划线且看起来像链接。如何使CustomLink在OHAttributedLabel中可触摸

但是,我无法点击/触摸链接。还有什么其他必须完成的文本范围内的addCustomLink方法? FWIW,即使大部分OHAttributedLabel代码引用IBOutlet,我都不使用Interface Builder。

回答

6

在这种情况下,所需的代码很干脆:

[myLabel setDelegate:self]; 

而且在上下文中为那些有兴趣的是:

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

非常感谢!