UITextView with HTML: how to display an image in local
To render the html in uitextview
, I used NSAttributedString. Seems to be OK, except that loading an image from a local file <img src=/var/mobile/Containers/...
doesn't work.
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;
}
+3
source to share