I have been searching this for hours but I've failed. I probably don't even know what I should be looking for.
Many applications have text and in this text are web hyperlinks in rounded rect. When I click them UIWebView
opens. What puzzles me is that they often have custom links, for example if words starts with # it is also clickable and the application responds by opening another view. How can I do that? Is it possible with UILabel
or do I need UITextView
or something else?
UITextView
supports data-detectors in OS3.0, whereasUILabel
doesn't.If you enable the data-detectors on the
UITextView
and your text contains URLs, phone numbers, etc. they will appear as links.I'm extending @samwize's answer to handle multi-line UILabel and give an example on using for a UIButton
Worked in Swift 3, pasting the entire code here
Create the class with the following .h and .m files. In the .m file there is the following function
Inside this function we will check the ranges of substrings for which we need to give actions. Use your own logic to put your ranges.
And following is the usage of the subclass
following is the .h file
following is the .m file
I had a hard time dealing with this... UILabel with links on it on attributed text... it is just a headache so I ended up using ZSWTappableLabel.