How to add tappable link into NSAttributedString

Sellen Wei
1 min readDec 12, 2018

--

I have been through this several times and it is hard to find a good tutorial to follow, here is some summery for that:

How to use UITextView, trade off is this tap must be long press tap, or iOS will ignore it, there are some third party cocoapods helper to solve this long press issue:

If you do not want to use UITextView, you could also use this way, use UITapGestureRecognizer to detect muti-line tapping and trigger an action, trade off is, it is hard to detect the location of link string:

If you are not working on anything complicate, the easiest way is just generate a button and overlap the part of String you want to have tappable link.

Some useful link translate muti-line string into strings objective c could directly use: http://multilineobjc.herokuapp.com/

And detail explanation about how to customize NSAttributedString (in Chinese): https://blog.csdn.net/Hello_Hwc/article/details/46731991

--

--