Xamarin Forms Webview Disable zoom on IOS platform

Viewed 50

I have a webview project in Xamarin, it can zoom on IOS platform but I want to disable it

 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

We have this tag in our HTML page, but it's still zoomable on IOS, how can I disable it?

1 Answers

You can try the following code in the webview renderer on the ios:

var source = "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);";
var script = new WKUserScript(new NSString(source), 
WKUserScriptInjectionTime.AtDocumentEnd, true);
wkWebView.Configuration.UserContentController.AddUserScript(script);

And if you need more information, you can check this link and this one.

Related