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图片的格式,有知道的大神们,帮忙留下一个答案,十分感谢!!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM