美文网首页
iOS,UITextView中显示html文本

iOS,UITextView中显示html文本

作者: iOS菜鸟攻城狮 | 来源:发表于2019-12-09 15:39 被阅读0次

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 30, 20, 114)];

textView.backgroundColor = [UIColor redColor];

[self.view addSubview:textView];

NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p>![](https://img-blog.csdnimg.cn/20190927151043371.png)";

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

textView.attributedText = attributedString;

相关文章

网友评论

      本文标题:iOS,UITextView中显示html文本

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