10

My iOS app has a WKWebView component which shows an full-screen WebApp (1280x800) with different aspect ratio and size then a iPad (4:3, 1024x768)

I want to set the WkWebView zoom factor to 0.8, to fit it in landscape mode. How can I control the zoom scale of the WkWebView?

I tried to set the the zoom scale of the WkWebView scrollview, but it doesn't scale for values below 1, even when I set the minimumZoomScale accordingly.

[self.webView.scrollView setMinimumZoomScale:0.8];

[self.webView.scrollView setZoomScale:0.8];

Does anyone have an idea why this doesn't work?

AJV
  • 101
  • 1
  • 1
  • 3
  • You might be able to do this by injecting js into the view, overriding html viewport tags: https://stackoverflow.com/a/46929673/1214800 – brandonscript Feb 06 '19 at 17:01
  • Every browser has the possibility to zoom in/out, without affecting the original html/js. I'm looking for something similar with the WKWebView component. I succeeded with an Android/Windows app, but so far not with an iOS app. How can I zoom in/out programatically from the iOS native code? – AJV Feb 07 '19 at 06:52

1 Answers1

28

Add <meta name="viewport" content="width=device-width, shrink-to-fit=YES"> to your HTML file.

It works as if you used scalePageToFit in UIWebView.

Jorge A Gomez
  • 473
  • 6
  • 15
  • This also helped me where a Vimeo video embedded in an iframe was showing much too small, as though it was zoomed out. – andygeers Sep 17 '20 at 12:12