程序员

swift - Lable转译HTML代码

2020-05-14  本文已影响0人  biubiuboom
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()
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读