html - 在 ios swift 中加载 html 字符串,UIWebView 除外

标签 html ios iphone swift xcode

我想在 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/

相关文章:

javascript - jQuery,在动画期间禁用悬停功能

java - 如何在 vaadin 中设置网格单元格样式

IOS - 如何在注销时禁用推送通知?

html - 我布局中的这些 div 不会居中。我什么都试过了

javascript - 如何使用 jQuery 获取 <td> 的值?

ios - 在 Swift 协议(protocol)上应用 self 约束与在协议(protocol)的扩展上应用 self 约束之间的区别

ios - 不同 NSURLConnection 的单例

iphone - 如何使用ldid?

iphone - 我可以将专为 iOS 模拟器构建的应用程序安装到第二个模拟器上吗?

iPhone SDK : UIScrollView does not scroll