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

相关文章:

  • 2022-02-28
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-11-29
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2022-02-15
  • 2021-08-12
相关资源
相似解决方案