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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With