如何检测 UILabel 文本中是否有 Link 并使其可点击 - Swift

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

我正在使用 UILabel 来包含一些文本。此文本有时可能包含一些链接,例如 http://www.google.comwww.google.com 甚至 google.com。如何检测这些链接并使文本可点击以在浏览器中打开。请指教。提前致谢。

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

textView.dataDetectorTypes = UIDataDetectorTypeLink; 

Swift 3:

textView.dataDetectorTypes = UIDataDetectorTypes()