Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling content in WKWebView

Tags:

swift

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.

like image 649
Maheswari Avatar asked Nov 22 '18 13:11

Maheswari


2 Answers

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
like image 174
Mohit Rochwani Avatar answered Oct 08 '22 02:10

Mohit Rochwani


Given a webView object of type WKWebView you can do

webView.contentMode = .scaleToFill
like image 31
Lorenzo Zanotto Avatar answered Oct 08 '22 01:10

Lorenzo Zanotto