How to de- and increase the font size with WKWebView?
Swift 5 solution:
Implement WKNavigationDelegate
and in viewDidLoad
:
webView.navigationDelegate = self
then in didFinish
:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let js = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='200%'"//dual size
webView.evaluateJavaScript(js, completionHandler: nil)
}
The codes suggested by Inna used to work but stopped working from iOS10.3. I did some research and found that we need to make a slight change to it, just changing "%%" to a single "%".
So JS code should be:
let js = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='\(fontSize)%'"
I got this info from Apple Developer forum. https://forums.developer.apple.com/thread/51079