简体   繁体   中英

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.

您可以改用UITextView并为链接设置检测:

textView.dataDetectorTypes = UIDataDetectorTypeLink; 

Swift 3:

textView.dataDetectorTypes = UIDataDetectorTypes()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM