美文网首页
Label和UITextView显示富文本

Label和UITextView显示富文本

作者: 舟_e9ce | 来源:发表于2019-04-17 13:43 被阅读0次

    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显示富文本是可以滑动的。

    相关文章

      网友评论

          本文标题:Label和UITextView显示富文本

          本文链接:https://www.haomeiwen.com/subject/tmtnwqtx.html