I’m working on an app for fun where I receive messages from a remote web service, like Twitter. Sometimes these messages contains URL:s, and I want to make these clickable. I wonder which approach would be the best. I have tried NSLinkAttributeName but it doesn’t work for iOS. Is it possible to create a transparent button and position it above the right place in the textview? And how could I do that? Or is there a better/easier way? The position and length of the url can vary.
Share
There are two good ways of going about this:
1. CoreText, or rather a wrapper around it like TTTAtributedLabel
That’s the most powerful solution. It supports Datadetectortypes (though you are better off doing your own detection for performance ahead of displaying it) and it’s relatively popular.
It might however affect your tableview’s scrolling performance depending on your usage.
2. Dynamically placing buttons above your labels like IFTweetLabel
That’s the easy solution. IFTweetLabel is basically a drop-in for UILabel and it performs really well out of the box. However, you will eventually run into its limits if you’re looking to customize it too much. Not to mention that it doesn’t behave perfectly 100% of the time. YMMV.