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

  • 相关阅读:
    打印机无法打印文件
    .Net com组件操作excel(不建议采用Com组件操作excel)
    Zebra
    Map遍历方式
    PageHelper原理
    MySQL8.0新特性
    算法_插入排序
    贝叶斯定理
    二叉树学习笔记
    Java校验时间段重叠
  • 原文地址:https://www.cnblogs.com/boyuanmeng/p/7245791.html
Copyright © 2011-2022 走看看