How to disable input zoom in WKWebView?

273 Views Asked by At

Can someone help me to get rid of automatic zoom while typing in input field of my website that is shown in WKWebView?

1

There are 1 best solutions below

1
Vikas Saini On

Try this code , it works for me :

let source: String = "var meta = document.createElement('meta');" +
            "meta.name = 'viewport';" +
            "meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';" +
            "var head = document.getElementsByTagName('head')[0];" + "head.appendChild(meta);";

        let script: WKUserScript = WKUserScript(source: source, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
        webView.configuration.userContentController.addUserScript(script)