【发布时间】:2017-11-24 08:49:36
【问题描述】:
我的标签中有一个 html 数据,以及如何使它们可点击。
我可以成功显示我的 html 数据,但我不知道如何转换它们。
有什么好的建议吗?
谢谢
这是我的标签代码:
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)
}
【问题讨论】:
-
使用
UITextView,而不是UILabel。UILabel不是可点击的。你可以做到,但这有点棘手,在 CocoaPods/GitHub/CocoaControls 等中已经有很多解决方案。更简单的方法是使用UITextView并稍加修改,它看起来就像一个 UILabel用户。 -
对不起,有样品给我吗?
-
对不起,我不知道如何重复。只是字符串链接我知道该怎么做。但是像我的图片这样的链接在我的 html 数据字符串中。我不知道该怎么做。