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;
}
set image src start with "file://" may solve this problem.