簡體   English   中英

帶HTML的UITextView:如何在本地顯示圖像

[英]UITextView with HTML: How to display image in local

要顯示HTML uitextview ,我用NSAttributedString。 看起來沒問題,除了從<img src=/var/mobile/Containers/...加載本地圖像不起作用。

我究竟做錯了什么?

// Save image in document
// Save path to imgPath
self.textContent = "<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='\(imgPath)' width=200 height=200 >"
if let htmlData = self.textContent.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: false) {
    var attributedString: NSAttributedString = NSAttributedString(data: htmlData, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil, error: nil)!
    self.txtView.attributedText = attributedString;
}
self.textContent = "<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src="file:///var/mobile/....." width=200 height=200 >"  

設置圖像src以“file://”開頭可以解決這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM