- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString * htmlString = @"<html><body> 事物联系人 <font color=\"red\">呵呵哒</font>的 <font color=\"red\">订单修改-修改价格</font> 事物 </body></html>";
NSAttributedString *str = [self getStringWithParagraphStyleFromHtmlString:htmlString];
self.textView.attributedText = str;
}
- (NSAttributedString *)getStringWithParagraphStyleFromHtmlString:(NSString *)string{
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithData:[string dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:3.5];
[attrStr addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, attrStr.length)];
return attrStr;
}
解析html字符串获取属性字符串
最新推荐文章于 2024-05-20 15:31:49 发布