self.contentStr
= “h5文本”
let data = self.contentStr.dataUsingEncoding(NSUnicodeStringEncoding)
do {
let attrStr = try NSAttributedString(data: data!, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], documentAttributes: nil)
webView.attributedText = attrStr
} catch let error as NSError{
print("error:\(error)")
}

本文介绍如何将HTML文本转换为NSAttributedString并显示在WebView中。通过使用NSUnicodeStringEncoding编码和NSAttributedString的数据初始化方法,可以实现从HTML到富文本的有效转换。
3312

被折叠的 条评论
为什么被折叠?



