Button action or similar in NSAttributedString

Is there a way to do something similar to the NSLinkAttribute attribute, but instead of opening the url, I want to run the action on iOS?

[attributedString addAttribute:NSLinkAttributeName value:@"http://www.google.com" range:range];
+3
source share
1 answer

I have found a solution.

There is a method in UITextViewDelegate:

textView:shouldInteractWithURL:inRange:

If you return NO, you can intercept the click and long click of the link.

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
    [self MAKE_YOUR_ACTION];
    return NO;
}

It works only in iOS7. In older versions, the only solution I found was what @Anc Ainu suggested in the comments on the question.

+2
source

All Articles