For such a case, instead of adding it as a UILabel
component, I would rather use UITextView
, because it has dataDetectorTypes property:
The types of data converted to tappable URLs in the text view.
You can use this property to specify the types of data (phone numbers,
http links, and so on) that should be automatically converted to URLs
in the text view. When tapped, the text view opens the application
responsible for handling the URL type and passes it the URL. Note that
data detection does not occur if the text view's isEditable property
is set to true.
So, you can implement it as:
// as mentioned in the documentation, make sure to let it be uneditable:
textView.isEditable = false
textView.dataDetectorTypes = .link
For your case, I assume that it shall be .link
. I would also suggest to check the other options for the UIDataDetectorTypes.