UILabel展示html文本

2017-05-03  本文已影响224人  努力奔跑的小男孩
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];
上一篇下一篇

猜你喜欢

热点阅读