iOS 如何在Label中显示html的文本

时间:2022-11-08 14:38:19
if (self.messageModel) {

        NSString * htmlString = self.messageModel.contentText;
NSAttributedString * attrStr1 = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; //就这句有用 self.messageTextView.attributedText = attrStr1; if () {
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"【重要】"];
[attrStr appendAttributedString:attrStr1];
NSRange range = NSMakeRange(, );
[attrStr addAttribute:NSForegroundColorAttributeName value:GNHGreenColor range:range];
self.messageTextView.attributedText = attrStr;
}
}

显示如下:

iOS 如何在Label中显示html的文本