0

I have a html data in my label, and how to make them clickable.
I can show my html data successful, but I don't know how to convert them.
Have any good suggestion to me?
Thanks

htmlData content here.

This is my label code:

let htmlData = ""

do {
        let attrStr = try NSAttributedString(
            data: htmlData.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
            options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
            documentAttributes: nil)
        self.label.attributedText = attrStr
    } catch let error {
        print(error)
    }

pic1

tolerate_Me_Thx
  • 387
  • 2
  • 7
  • 21
  • Use a `UITextView`, not a `UILabel`. `UILabel` are not meant to be clickable. You can make it, but it's kind of tricky, and there are already plenty of solution in CocoaPods/GitHub/CocoaControls, etc. The easier way is to use a `UITextView` and with small modifications, it can looks like a UILabel for the user. – Larme Nov 24 '17 at 09:35
  • Sorry ,have any sample to me? – tolerate_Me_Thx Nov 24 '17 at 09:54
  • 1
    Possible duplicate of [NSAttributedString click event in UILabel using swift](https://stackoverflow.com/questions/38565603/nsattributedstring-click-event-in-uilabel-using-swift) – Larme Nov 24 '17 at 10:44
  • sorry, I dont know how duplicate. Just string link I know how to do. But my link like my picture is in my html data string. I don't know how to do. – tolerate_Me_Thx Nov 25 '17 at 02:33

1 Answers1

1

Label may not detect hyperlinks, but "webView" does.

webView.loadHTMLString(dataHtmlString, baseURL: nil)
Nilomi Shah
  • 186
  • 7