ios swift Lable转译HTML代码

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()
        }
    }
}

你可能感兴趣的:(ios swift Lable转译HTML代码)