Bullionist
Bullionist

Reputation: 2210

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.

Upvotes: 2

Views: 9241

Answers (2)

Suhaib
Suhaib

Reputation: 2061

Swift 3:

textView.dataDetectorTypes = UIDataDetectorTypes()

Upvotes: 1

rocky
rocky

Reputation: 3541

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

textView.dataDetectorTypes = UIDataDetectorTypeLink; 

Upvotes: 7

Related Questions