WKWebView加载本地html遇到的坑与解决办法

1、字体变小解决办法

Swift
let headerString = "
" self.wkwebview.loadHTMLString(headerString.appending(html), baseURL: nil)
Objective-C
NSString *headerString = @"
"; [strongSelf.contentWebView loadHTMLString:[headerString stringByAppendingString:model.detail] baseURL:nil];

2、空格太大的解决办法

遇到iOS的空格比安卓大很多

// 去掉所有空格
html = htmlStr.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "
 ", with: "")

当html中有表格且格子里是空的,与要加上空格

//给空表格中间加空格
html = html.replacingOccurrences(of: "", with: " ")

3、调整图片显示边距,视频边距,行间距,表格边距

//css
        let htmlString = String(format:"%@",html)

4、设置html中视频播放时不进入全屏

//先设置WKWebViewConfiguration
let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = true
wkwebview = WKWebView(frame: .zero, configuration: configuration)

//调用js设置
//防止有多个视频
guard self.totalHtml.contains("

你可能感兴趣的:(WKWebView加载本地html遇到的坑与解决办法)