NSString * htmlString =@"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
NSAttributedString * attrStr = [[NSAttributedStringalloc] initWithData:[htmlStringdataUsingEncoding:NSUnicodeStringEncoding]options:@{ NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType } documentAttributes:nilerror:nil];
UILabel * myLabel = [[UILabelalloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; // 这里可以结合 自动布局(Masary),让label 自动扩充
myLabel.attributedText = attrStr;
[self.viewaddSubview:myLabel];
网友评论