0

I want to open two urls which are in an UILabel.

So far I managed to highlight the keywords in the Label as url with NSMutableAttributedString but I am not able to click on it / open it. I know it's kinda easy if I just use an UITextView but I want to use an UILabel.

let lastLabel: UILabel = {
    let label = UILabel()
    let attributedString = NSMutableAttributedString(string: "If you click on register, you accept the privacy policy and the terms and conditions.")
    return label
}()

...

    let termsUrl = URL(string: *the first url*)!
    let privacyUrl = URL(string: *the second url*)!
    attributedString.setAttributes([.link: termsUrl], range: NSMakeRange(41, 14))
    attributedString.setAttributes([.link: privacyUrl], range: NSMakeRange(64, 20))
    lastLabel.attributedText = attributedString

The words "privacy policy" and "terms and conditions" are blue and underlined, but I cant click/open it what I would expect to be possible.

  • 2
    Possible duplicate of [Create tap-able "links" in the NSAttributedString of a UILabel?](https://stackoverflow.com/questions/1256887/create-tap-able-links-in-the-nsattributedstring-of-a-uilabel) – denis_lor Apr 15 '19 at 14:19
  • Check second most voted answer here in Swift: https://stackoverflow.com/a/35789589/3564632 – denis_lor Apr 15 '19 at 14:20

0 Answers0