Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set iOS WkWebview zoom scale

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?

like image 686
AJV Avatar asked Feb 06 '19 16:02

AJV


People also ask

What is the difference between UIWebView and WKWebView?

Difference Between UIWebview and WKWebViewUIWebview is a part of UIKit, so it is available to your apps as standard. You don't need to import anything, it will we there by default. But WKWebView is run in a separate process to your app,. You need to import Webkit to use WKWebView in your app.

Is WKWebView the same as Safari?

WKWebView - This view allows developers to embed web content in your app. You can think of WKWebView as a stripped-down version of Safari. It is responsible to load a URL request and display the web content. WKWebView has the benefit of the Nitro JavaScript engine and offers more features.

How do I add WKWebView to my storyboard?

First add the web view as a UIWebView outlet in the storyboard / IB. This will give you a property like this: @property (weak, nonatomic) IBOutlet UIWebView *webView; Then just edit your code to change it to a WKWebView.

How do I refresh WKWebView?

The WKWebView already contains a scrollview. All you need to do is create the refresh control, assign a target function that will get called when a user initiates a refresh, and attach the refresh control to the scrollview.


1 Answers

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.

like image 99
Jorge A Gomez Avatar answered Oct 17 '22 00:10

Jorge A Gomez