2016-07-15 38 views
0

我想在Uitableview cell中加載下面的html字符串。如何加載它?在ios swift中加載html字符串,除了UIWebView

<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> 
+0

是UILabel的這個字符串嗎? – xmhafiz

+0

是.String被加載到標籤 – Madhumitha

+0

結帳RTLabel [鏈接](https://github.com/honcheng/RTLabel) –

回答

0

您可以的UILabel使用NSAttributed String負載或使用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

否則,如果您需要第三方的lib使用RTLabel它會加載標籤中的所有字符串類型

+0

或者使用編碼類型作爲'NSUTF16StringEncoded' –

+0

得到錯誤類型'String'沒有成員'.DocumentAttribute' – Madhumitha

0

那麼你必須要在你的表視圖格網的觀點,因爲沒有webview如何可以加載html string。根據我的知識,不可能加載html query,但UIWebView除外。

因此,你可以在tableview的單元格中使用UIWebView,並且可以在cellforrowatindexpath方法中將html加載到該webview。