문제

Is there a way to do something similar to the attribute NSLinkAttribute but instead of open an url I want trigger an action on iOS?

[attributedString addAttribute:NSLinkAttributeName value:@"http://www.google.com" range:range];
도움이 되었습니까?

해결책

I found a solution.

In UITextViewDelegate, there is a method:

textView:shouldInteractWithURL:inRange:

If you return NO, you can intercept the click and the longclick 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 the one suggested by @Anc Ainu in the comments of the question.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top