在uitextview
中显示html ,我使用了 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 >"
设置图像源以“file://”开头可能会解决这个问题。
关于html - 带有 HTML : How to display image in local 的 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31099310/