【问题标题】:load html string in ios swift except UIWebView在ios swift中加载html字符串,除了UIWebView
【发布时间】:2016-11-18 06:38:02
【问题描述】:

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

【问题讨论】:

标签: html ios iphone swift xcode


【解决方案1】:

您可以使用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,它将在标签中加载所有类型的字符串

【讨论】:

  • 收到错误类型'String'没有成员'.DocumentAttribute'
【解决方案2】:

然后您必须在表格视图单元格中获取网络视图,因为没有webview,您如何加载html string。据我所知,除了UIWebView 之外,无法加载html query

因此,您可以将UIWebView 放在tableview 的单元格中,并可以在cellforrowatindexpath 方法中将html 加载到该webview。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    相关资源
    最近更新 更多