Add a regular action to an NSAttributedString?

五迷三道 提交于 2019-12-01 11:23:59

You can use NSLinkAttributeName itself to achieve this. Use an attributed string as shown below and set it as the text of a UITextView.

 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:termsString];
        [attributedString addAttribute:NSLinkAttributeName value:url range:range];
[myTextView setAttributedText:attributedString];

And then override the UITextView delegate method:

-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{

// Call your method here.
return YES;
}

Dont forget to set the delegate of your textView!

Also, you can just make a simple transparent UITouch like control on top it. It means that you need to fake it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!