I recently started working on WKWebView and have minimum knowledge about it.
I want to know how to scale the content in the WKWebView so that it fits into the given view size without scrolling.
I have tried setting the height of the view to be screen size and load some large html content to the WKWebView and disable scrolling. Then only a part of the content is shown.
Then I searched for the approach to scale the content of the WKWebView so that the entire content is seen without need for scrolling.
Many people have posted questions regarding this but some questions were still unanswered and some other solutions did not work for me.
For the WKWebView try the following three options depending upon your requirement:
webview being the webview in your file
webView.contentMode = .scaleAspectFill
or
webView.contentMode = .scaleAspectFit
or
webView.contentMode = .scaleToFill
Given a webView object of type WKWebView you can do
webView.contentMode = .scaleToFill
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