A Clickable Link on a Swift Label or TextView
Embedded links on a NSAttributedString
Wouldn’t it be slightly disappointing if we couldn’t click on links on a webpage. Or could only click on one in each passage of text?
This article is designed to help you write a clickable UILabel or UITextView.
It seems easy to create a link on a label in a Swift iOS App. It is, if you want the easy way. If you want the fantastic way you might have to put in a little more work.
In the case of the latter, you are welcome to read on and find out how to do this in a nice and tidy way.
That is, the goal is that we want a String where if you click on the link portion of the String it acts like a link. If you click on another part of the String it does not act as a link.
Difficulty: Easy | Normal | Challenging
Prerequisites:
- You just need to know what effect you are actually looking for from your link, and follow through this tutorial post.
Terminology
NSAttributedString: is a piece of text that has attributes (like links or fonts) that apply to portions of text.