美文网首页
iOS UILabel与UITextView加载HTML

iOS UILabel与UITextView加载HTML

作者: 木登与木由 | 来源:发表于2018-07-30 16:53 被阅读213次

1、转换为NSMutableAttributedString

 NSMutableAttributedString *htmlStr = [[NSMutableAttributedString alloc] initWithData:[@"字符串" dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
    
    // 字体大小
 [htmlStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, htmlStr.length)];

2、接收转换后的内容

_lab.attributedText = htmlStr;

相关文章

网友评论

      本文标题:iOS UILabel与UITextView加载HTML

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