To display html in uitextview, I used NSAttributedString. It seems OK, except loading an image from local by <img src=/var/mobile/Containers/... is not working.
What am I doing wrong?
// 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 >"
set image src start with "file://" may solve this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With