iOS UILabel与UITextView加载HTML

2018-07-30  本文已影响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;
上一篇 下一篇

猜你喜欢

热点阅读