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;