我想顯示在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