iOS,UITextView中显示html文本

iOS,UITextView中显示html文本,第1张

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

textView.backgroundColor = [UIColor redColor]

[self.view addSubview:textView]

NSString *htmlString = @"<h1>Header</h1><h2&gtSubheader</h2>&ltp>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

UITextView*textView = [[UITextViewalloc]initWithFrame:CGRectMake(20,30,100,199)]

textView.backgroundColor = [UIColor redColor]

[self.view addSubview:textView]

NSString *htmlString = @"<h1>header</h1><h2>Subheader</h2><p>Some<em>text</em></p>![](http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg)"

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

textView.attributedText = attributedString


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7185851.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-02
下一篇 2023-04-02

发表评论

登录后才能评论

评论列表(0条)

保存