UIWebView加载本地HTML文件

有时候需求需要将本地的html文件加载到webView上面,不废话,直接贴代码:

关键代码:加载文件

HTML文件路径

HTML文件路径

引入HTML文件夹时,不可选择平常引入文件使用的Create Groups:

不可用Create Groups

    //js获取body宽度
    NSString *bodyWidth= [webView stringByEvaluatingJavaScriptFromString: @"document.body.scrollWidth "];
    float widthOfBody = [bodyWidth floatValue];
    //获取实际要显示的html
    NSString *html = [self htmlAdjustWithPageWidth:widthOfBody html:_htmlStr webView:webView];
    //设置为已经加载完成
    _isLoadingFinished = YES;
    [webView sizeToFit];
    //加载实际要现实的html
    NSString * htmlcontent = [NSString stringWithFormat:@"
%@
", html]; [webView loadHTMLString:htmlcontent baseURL:nil];
文章目录
  1. 1. 有时候需求需要将本地的html文件加载到webView上面,不废话,直接贴代码:
  2. 2. HTML文件路径
  3. 3. 引入HTML文件夹时,不可选择平常引入文件使用的Create Groups:
,