Swift3.0下,UILabel加载html,实现富文本

func layoutWithActivityModel(model:ActivityModel){
        do{
            let attrStr = try NSAttributedString(data: model.title!.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            let txtAttrStr = try NSAttributedString(data: model.content!.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            TxTLabel.attributedText = txtAttrStr
            titleLabel.attributedText = attrStr
        }catch let error as NSError {
            print(error.localizedDescription)
        }
        
    }

上述方法是写在UITableViewCell中给cell上的UILabel赋值;


 {  content = "11\U6708HR\U3001Diro\U6b63\U54c1\U7f8e\U5986\U6b63\U54c10\U5143\U53ef\U8d2d";
    title = "\U8d85\U503c\U6708\U8d2d";
 }
{ content = "\U5f85\U8fd4\U91d1\U989d4\U5468\U540e\U53ef\U63d0\U73b0,\U5347\U7ea7\U63d0\U901f7\U5929!";
  title = "\U6781\U901f\U63d0\U73b0";
 }
{content = "\U9a6c\U4e0a\U5230\U6765,\U656c\U8bf7\U671f\U5f85";
title = "\U7cbe\U54c1\U5c1d\U9c9c";
}

以上是下发的html标签


Swift3.0下,UILabel加载html,实现富文本_第1张图片
效果图

你可能感兴趣的:(Swift3.0下,UILabel加载html,实现富文本)