美文网首页
iOS UITextView UILabel 显示 HTML内容

iOS UITextView UILabel 显示 HTML内容

作者: wzf_taker | 来源:发表于2016-05-13 15:21 被阅读1482次

iOS6 之后的UITextView和UILabel 有attributedText 属性,可以设置字符串显示的多样化显示。

``
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p>

";
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
textView.attributedText = attributedString;

``

相关文章

网友评论

      本文标题:iOS UITextView UILabel 显示 HTML内容

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