我想显示在iOS应用下面的HTML文本如何斯威夫特解码HTML格式文本3
<p><span style="color: #000000;">Experience royalty in all its splendor</span><br /><span style="color: #000000;"> An address that is a possession of pride</span></p>
我NSAttributedString尝试和附加字体在HTML字符串,但没有什么工作
let st:String = pjt.value(forKey: "description") as! String // Original content from API - "<p><span style="color: #000000;">Experience royalty in all its splendor</span><br /><span style="color: #000000;"> An address that is a possession of pride</span></p><........"
let desc:Data = st.data(using: String.Encoding.utf8, allowLossyConversion: true)!
//st.data(using: String.Encoding.utf16)!
do {
let attrStr = try NSAttributedString(data: desc, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], documentAttributes: nil)
print("Attr STr \(attrStr)")
self.textView.attributedText = attrStr;
}
它也没有在网页视图中工作与self.webView.loadHTMLString(st, baseURL: nil)
更新
Textview或webview或标签全部显示相同的纯html字符串<p><span style="color: #000000;">Experience royalty in all its splendor</span><br /><span style="color: #000000;"> An address that is a possession of pride</span></p>
任何帮助吗?
注意:斯威夫特3个
谢谢!
显示一些额外的代码 –
您'让ST:String'错误检查一次更新之前的字符串 –
@ Anbu.Karthik好 – Gopik