iOS UILabel与UITextView加载HTML

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)