Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uiwebview zoom programmatically

I want to change the UIWebView zoom level programmatically.

I have tried these but they are not worked for me ;

    UIScrollView *sv = [theWebView.subviews objectAtIndex:0];
 [sv setZoomScale:50 animated:YES];

also,

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

Any idea?

like image 377
Can Avatar asked Apr 15 '26 10:04

Can


2 Answers

This is the only way I could find to accomplish it: (specify your own sizes if you wish, i was attempting to zoom out after typing into a form field)

UIScrollView *sv = [[webViewView subviews] objectAtIndex:0];
[sv zoomToRect:CGRectMake(0, 0, sv.contentSize.width, sv.contentSize.height) animated:YES];
like image 54
Captnwalker1 Avatar answered Apr 18 '26 08:04

Captnwalker1


I would use:

UIScrollView * sv = self.theWebview.scrollView;

[sv setZoomScale:50];

where self is the viewController containing the webView.

Your problem could be the size of your zoomScale exceeds the size of sv.maximumZoomScale.

like image 45
Carl Carlson Avatar answered Apr 18 '26 08:04

Carl Carlson