显示html文本一般用webView但是有时侯我们只是显示文本而且又涉及到表格复用。用webView会让费资源,这时可以用textView显示
//设置文本宽高,涉及到图片必须添加这个
NSString *htmlStr = [NSString stringWithFormat:@"<head><style>img{width:%f}</style></head>%@",SCREEN_WIDTH - 30,_model.content];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlStr dataUsingEncoding:NSUnicodeStringEncoding]
options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
self.textView.attributedText = attributedString;
- (UITextView *)textView {
if (!_textView) {
_textView = [[UITextView alloc] init];
_textView.font = [UIFont systemFontOfSize:13];
_textView.textColor = [UIColor LFTextNormalColor];
_textView.scrollEnabled = NO;
_textView.editable = NO;
}
return _textView;
}
网友评论