Shaik MD Ashiq Shaik MD Ashiq - 2 months ago 42
Swift Question

How to detect if there is a Link in UILabel text and make it clickable - Swift

I am using a

UILabel
to contain some text. This text may sometimes contain some links like http://www.google.com or www.google.com or even google.com. How do I detect these links and make the text clickable to open in a browser. Please advice. Thanks in advance.

Answer

You can use a UITextView instead and set detection for links:

textView.dataDetectorTypes = UIDataDetectorTypeLink; 
Comments