简体   繁体   English

标签显示html数据并使图片和链接可快速点击

[英]Label shows the html data and make image and link clickable by swift

I have a html data in my label, and how to make them clickable. 我的标签中有一个html数据,以及如何使它们可点击。
I can show my html data successful, but I don't know how to convert them. 我可以成功显示html数据,但是我不知道如何转换它们。
Have any good suggestion to me? 对我有什么好的建议吗?
Thanks 谢谢

htmlData content here. htmlData内容在这里。

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

标签可能无法检测到超链接,但“ webView”可以。

webView.loadHTMLString(dataHtmlString, baseURL: nil)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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