swift label 显示html文本
2019-04-10 本文已影响0人
晨煜煌
let html = "htmlText: <font color='#FF8B2F'>111111</font>"
do {
if let data = html.data(using: String.Encoding.unicode, allowLossyConversion: true) {
let attStr = try NSAttributedString.init(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html,], documentAttributes: nil)
titleLabel.attributedText = attStr
}
} catch {
titleLabel.text = html
}