ios端简单改变webView的黑白夜模式
extension HTController:WKUIDelegate, WKNavigationDelegate,WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "setTitle" {
let body = message.body
print(NSLocalizedString("点击了这个方法\(body)", comment: ""))
}
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let colorStyle:String = kUserDefaults.string(forKey: "ColorStyle")!
if colorStyle != "day" {
webView.evaluateJavaScript("document.getElementsByTagName('body')[0].style.background='#333333'", completionHandler: nil)
webView.evaluateJavaScript("document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'white'", completionHandler: nil)
webView.evaluateJavaScript("document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '300%", completionHandler: nil)
}else{
webView.evaluateJavaScript("document.getElementsByTagName('body')[0].style.background='#ffffff'", completionHandler: nil)
webView.evaluateJavaScript("document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'black'", completionHandler: nil)
webView.evaluateJavaScript("document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '300%", completionHandler: nil)
}
}
}