您的位置:首页 > 移动开发

iOS UIWebView UITextView UILabel 显示 HTML内容

2016-10-15 09:44 489 查看
// 获取html到NSString

 NSURL *url = [NSURL URLWithString:@"http://xxx/xxx/xxx"];

 NSString *strHtml = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

   

// 显示到UIWebView

 [webView loadHTMLString:strHtml baseURL:nil];

   

// 显示到UITextView
(用不了)

  [textView setContentToHTMLString:strHtml];

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

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

 textView.attributedText = attributedString;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: