iOS 如何在Label中显示html的文本
2024-08-26 15:01:50
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-appStore发布流程
- Unable to get valid context for root
- 简单实用的PHP验证码类
- synchronized关键字使用剖析
- %r与%s的区别
- Test-NetConnection
- Java批处理操作
- PhotoSwipe简介
- KingbaseES的DBLink创建
- Log POST Data in Nginx
- BZOJ 4553 Tjoi2016&;Heoi2016 序列
- iOS 8 UIAlertController 和 UIAlertAction
- mssql sqlserver 将字段null(空值)值替换为指定值的三种方法分享
- 04-MirrorGate安装脚本备注
- HDU - 1160 (FatMouse's Speed )最长上升子序列
- GYM 101173 K.Key Knocking(构造)
- Template literals
- Linux tomcat
- python使用input()来接受字符串时一直报错“xxx is not defined”
- TestNG参数