UILabel显示html文本

NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";  

NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; 

UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];  

myLabel.attributedText = attrStr;  

[self.view addSubview:myLabel]; 

posted @ 2016-03-26 15:33  我不是冰红茶  阅读(678)  评论(0编辑  收藏  举报