使用样例(Swift为例)
//开始返回内容(WKNavigationDelegate代理方法)
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
//页面字体放大1.2倍显示
let fontScale = 120
let jsString = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust = '\(fontScale)%'"
webView.evaluateJavaScript(jsString) { result, error in
}
}
//页面加载成功
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
}
改变字体大小
document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust = '120%'
document.getElementsByTagName('html')[0].style.fontSize = '120%'
改变字体颜色
document.getElementsByTagName('body')[0].style.webkitTextFillColor = '#FF6A6A'
网友评论