Question

I have an NSTextAttachment with an image in a UILabel and I would like to perform a custom behaviour when clicking on this attachment.

UITextViewDelegate provides an handy method

textView:shouldInteractWithTextAttachment:inRange:

But it can only be used if I'm using UITextView.

Is there any solution if Im using UILabel?

Thanks!

No correct solution

OTHER TIPS

The text attachment becomes part of the model and is treated like a character, so try adding a link to the range of your attachment. Like this:

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)];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top