美文网首页程序员
swift - Lable转译HTML代码

swift - Lable转译HTML代码

作者: biubiuboom | 来源:发表于2020-05-14 18:39 被阅读0次
extension String{
    func convertHtml() -> NSAttributedString{
        guard data(using: .utf8) != nil else { return NSAttributedString() }
        do {
            return try NSAttributedString(data: Data(utf8),
                                          options: [.documentType: NSAttributedString.DocumentType.html,
                                                    .characterEncoding: String.Encoding.utf8.rawValue],
                                          documentAttributes: nil)
        } catch {
            print("error:", error)
            return NSAttributedString()
        }
    }
}

相关文章

网友评论

    本文标题:swift - Lable转译HTML代码

    本文链接:https://www.haomeiwen.com/subject/sozdnhtx.html