美文网首页
iOS UILabel显示HTML文本

iOS UILabel显示HTML文本

作者: 明明的魔样 | 来源:发表于2017-06-25 22:01 被阅读157次

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];

相关文章

网友评论

      本文标题: iOS UILabel显示HTML文本

      本文链接:https://www.haomeiwen.com/subject/fvcmpttx.html