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
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
- (void)viewDidLoad{
[super viewDidLoad]
NSString *strHTML = @"<p>你好</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp这是一个例子,请显示</p><p>外加一个table</p><table><tbody><tr class=\"firstRow\"><td valign=\"top\" width=\"261\">aaaa</td><td valign=\"top\" width=\"261\">bbbb</td><td valign=\"top\" width=\"261\">cccc</td></tr></tbody></table><p><br/></p>"
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame]
[self.view addSubview:webView]
[webView loadHTMLString:strHTML baseURL:nil]
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)