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

iOS UILabel显示HTML文本

作者: 浪漫紫薇星 | 来源:发表于2016-05-31 20:40 被阅读3108次

只能在iOS7以后运行


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

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/dothdttx.html