我想在 Uitableview 单元格中加载以下 html 字符串。如何加载它?
<p>\r\n\t Whether you are viewing a premium-quality 2D picture or seeing incredible 3D depth, images are breathtakingly real in Samsung Full HD. Combine with a 3D TV and 3D active shutter glasses to view the latest Hollywood 3D titles or amplify your viewing experience by upconverting 2D content to immersive 3D.\r\n</p>
最佳答案
您可以使用NSAttributed String
在UILabel中加载或使用UItextView
加载HTML字符串,例如
let htmlString: String = "<p>\r\n\t Whether you are viewing a premium-quality 2D picture or seeing incredible 3D depth, images are breathtakingly real in Samsung Full HD. Combine with a 3D TV and 3D active shutter glasses to view the latest Hollywood 3D titles or amplify your viewing experience by upconverting 2D content to immersive 3D.\r\n</p>"
let attrStr: NSAttributedString = try! NSAttributedString(data: htmlString.dataUsingEncoding(NSUnicodeStringEncoding), options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
yourlabel.attributedText = attrStr
有关其他帮助,请参阅 this
否则,如果您需要第三方库,请使用 RTLabel它将加载标签中所有类型的字符串
关于html - 在 ios swift 中加载 html 字符串,UIWebView 除外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38389544/