如何让Label等控件支持HTML格式的代码? 使用NSAttributedString:

> 如何让Label等控件支持HTML格式的代码? 使用NSAttributedString:

NSString *htmlString = @"
Tate《iOS Develop Tips》get Tate_zwt 打赏 100 金币
"; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType } documentAttributes:nil error:nil];_contentLabel.attributedText = attributedString;

>如何让Label等控件同时支持HTML代码和行间距?

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[_open_bonus_article dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType } documentAttributes:nil error:nil];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];[paragraphStyle setLineSpacing:12]; //调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])];
_detailLabel.attributedText = attributedString;[_detailLabel sizeToFit];

你可能感兴趣的:(如何让Label等控件支持HTML格式的代码? 使用NSAttributedString:)