html - 带有 HTML : How to display image in local 的 UITextView

标签 html ios image uitextview nsattributedstring

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/

相关文章:

image - IE 10 和 PNG 文件作为背景图像

ios - UITableview 单元格高度在 IOS7 中不起作用

jquery - 使用 CSS(或 jQuery)放大图像而不移动页面上的其他所有内容

html - 创建半透明图像叠加层

javascript - Chrome 以外的浏览器中的语音识别?

ios - 带有显示更多按钮操作的动态标签和单元格高度

ios - KeychainItemWrapper 迁移数据抛出错误

css - 具有 3 列 100% 宽度/高度的跨浏览器兼容 CSS 液体布局

javascript - 使用固定元素和调整大小的 HTML CSS

jquery - 算法对 Angular 淡入淡出jquery