Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView set initial zoom scale programmatically when loading an external website?

What I want to do is set the initial zoom scale [and in some cases, content offset, but that is less important] for an external website. But after the app initially sets the zoom and offset, the user should be able to change them, and the app should not interfere.

Some related information is available here, here, and here. But as far as I can tell, none of does what I want.

The meta setting approach looks promising -- but how would I set it when I don't control the html content that will be loaded?

like image 406
William Jockusch Avatar asked Nov 06 '11 15:11

William Jockusch


1 Answers

Try this for setting the initial zoom level -

[webView stringByEvaluatingJavaScriptFromString:@"document. body.style.zoom = 5.0;"];

Also dont forget to set scalesPageToFit to NO and you're done.

If you set this to YES, the webpage is scaled to fit and the user can zoom in and zoom out. If NO, user zooming is disabled. The default value is NO.

like image 138
Srikar Appalaraju Avatar answered Apr 29 '23 13:04

Srikar Appalaraju