1、获取html字符串,字符串转化成data,关键注意
[NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html]
等同于
[.documentType: NSAttributedString.DocumentType.html]
完整代码
let attrStr = try! NSAttributedString(data: orgAnnouncementM.post_content.data(using: .utf8, allowLossyConversion: true)!, options:[.documentType: NSAttributedString.DocumentType.html,.characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
textView1.attributedText = attrStr
个人提示:
用label显示富文本是不能滑动的,用UITextView显示富文本是可以滑动的。
网友评论