It's trivial to make hyperlinks clickable in a UITextView
. You just set the "detect links" checkbox on the view in IB, and it detects HTTP links and turns them into hyperlinks.
However, that still means that what the user sees is the "raw" link. RTF files and HTML both allow you to set up a user-readable string with a link "behind" it.
It's easy to install attributed text into a text view (or a UILabel
or UITextField
, for that matter.) However, when that attributed text includes a link, it is not clickable.
Is there a way to make user-readable text clickable in a UITextView
, UILabel
or UITextField
?
The markup is different on SO, but here is the general idea. What I want is text like this:
This morph was generated with Face Dancer, Click to view in the app store.
The only thing I can get is this:
This morph was generated with Face Dancer, Click on http://example.com/facedancer to view in the app store.
Use UITextView and set dataDetectorTypes for Link.
like this:
If you want to detect link, phone number,address etc..then
I too had a similar requirement, initially I used UILabel and then I realized that UITextView is better. I made UITextView behave like UILabel by disabling interaction and scrolling and made a category method for
NSMutableAttributedString
to set link to text same as what Karl had done (+1 for that) this is my obj c versionyou can use the below delegate then to handle the action
In case you're having issues with what @Karl Nosworthy and @esilver had provided above, I've updated the NSMutableAttributedString extension to its Swift 4 version.