2013-11-03 54 views
0

我有一个NSTextAttachment,其中的图像位于UILabel中,我希望在单击此附件时执行自定义行为。ios7与uilabel中的nstextattachment进行自定义交互

UITextViewDelegate提供了一种方便的方法

textView:shouldInteractWithTextAttachment:inRange: 

但是,如果我用UITextView它只能使用。

如果我使用UILabel,是否有解决方案?

谢谢!

回答

1

文本附件成为模型的一部分,并被视为字符,因此请尝试添加指向附件范围的链接。 喜欢这个:

NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil]; 
attachment.image = [UIImage imageNamed:@"myImage"]; 

NSAttributedString *imageString = [NSAttributedString attributedStringWithAttachment:attachment]; 
NSMutableAttributedString *mutableImageString = [imageString mutableCopy]; 
[mutableImageString addAttribute:NSLinkAttributeName value:@"http://stackoverflow.com" range:NSMakeRange(0, mutableImageString.length)]; 
相关问题