webview 本地 html空白,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("
return
}
let arr = totalHtml.components(separatedBy: "
for i in 0 ..< arr.count {
//設置視頻在webview 上播放
let webkitPlaysinline = "document.getElementsByTagName('video')[\(i)].setAttribute('webkit-playsinline', true)"
webView.evaluateJavaScript(webkitPlaysinline, completionHandler: { (data, error) in
printLog(message: data)
})
let x5Playsinline = "document.getElementsByTagName('video')[\(i)].setAttribute('x5-playsinline', true)"
webView.evaluateJavaScript(x5Playsinline, completionHandler: { (data, error) in
printLog(message: data)
})
let playsinline = "document.getElementsByTagName('video')[\(i)].setAttribute('playsinline', true)"
webView.evaluateJavaScript(playsinline, completionHandler: { (data, error) in
printLog(message: data)
})
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的webview 本地 html空白,WKWebView加载本地html遇到的坑与解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php rpoplpush,RPOPLP
- 下一篇: vb.net中递归退到最外层_数组中的逆