ios - 在 UITextView 中显示 HTML 字符串

标签 ios swift uitextview nsattributedstring

我试图在 UITextView 中显示一个 HTML 字符串。这是关键行:

self.postPage.attributedText = NSAttributedString(string: myHTMLString)

我看到的问题是 <div>标签 <img>标签仍在显示...我做错了什么吗?

最佳答案

extension String {
    var html2String:String {
        return NSAttributedString(data: dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil, error: nil)!.string
    }
}

"<div>Testing<br></div><img src=\"http://....\">".html2String  // "Testing\n"

关于ios - 在 UITextView 中显示 HTML 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27576302/

相关文章:

ios - 详细使用UITableView,如何在TextView中显示字符串(Master-Detail项目,Swift,iOS)

ios - 从 Parse 数据库循环 JSON 给出错误的结果

ios - 使用 UITextView 定制数据检测

ios - UITextView 右对齐 [不正确的行为]

objective-c - 使用 ARC 手动保留

ios - NSTextAttachment 在 UILabel 中的位置?

iphone - 取消本地通知时删除角标(Badge)编号

swift 3 : Not able to store Token value in another String

arrays - 如何从 Swift 中的数组中获取包含子元素的项?

ios - 如何以编程方式在当前光标位置的 UITextView 中输入文本