iOS UITextView 富文本显示html标签

   一般来说iOS端显示html标签用的都是UIWebView或WKWebView,做的比较方便快捷,但是加载速度也是比较慢的,所以这里记录并推荐一种比较简单的方式:

///显示富文本
+(NSAttributedString *)showAttributedToHtml:(NSString *)html withWidth:(float)width{
//替换图片的高度为屏幕的高度
    NSString *newString = [html stringByReplacingOccurrencesOfString:@"<img" withString:[NSString stringWithFormat:@"<img width=\"%f\"",width]];
   
    NSAttributedString *attributeString=[[NSAttributedString alloc] initWithData:[newString dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
    
    
    return attributeString;

}

 

加载html标签的速度有所提升,不过却在此发现一个问题,无论是webView还是富文本都不支持jpeg图片的格式,有知道的大神们,帮忙留下一个答案,十分感谢!!

posted @ 2017-07-27 16:53  筱筱心意  阅读(5794)  评论(0编辑  收藏  举报