2013-11-03 56 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)]; 
相關問題