adding hyper text to text on textview
How to add hypertext on a text on text v开发者_如何学Ciew.
I just did this in my app. It's complicated and will take a lot of work and a lot of thinking about how to implement it. You need to do 3 things. 1) implement a url scheme so that your application responds when hyperlinks are clicked. This way if you have a hyperlink to some text in your text view then your application can respond. 2) figure out a scheme for the hyperlinks so that your application can figure out where in your text the hyperlink points. 3) you need to add that scheme as a custom attribute to text in your text view. This sets up the text as being linkable.
This way when a link is clicked, your application receives the url, then you decompose the url extracting out the "custom attribute" part, then you search your text view for that custom attribute and when you find it you highlight the text... which makes the text linkable.
Here's 2 questions I posted about doing this that led me to the right answers. Create hyperlink to some text in NSTextView Saving custom attributes in NSAttributedString
精彩评论