I have an UIWebView with a pdf-file. It works fine. But how can i enable zooming on the pdf-file?
6 Answers
Make sure you checked "Scales page to fit"

- 2,949
- 1
- 16
- 6
-
Do you have any suggestion regarding zooming performance on PDF? I have an annoying black effect on zooming. – 0wn3r Apr 15 '14 at 09:08
-
1it enables zooming, but changes the initial scale factor – Daniel Sep 22 '14 at 11:09
-
Work's but this cause problems with other things.. for example http://stackoverflow.com/questions/33617217/uiwebview-problems-with-scale-and-scalespagetofit – jose920405 Nov 09 '15 at 22:05
-
Works for me. Thanks! – businesscasual Aug 27 '16 at 07:17
you can use webView.scalesPageToFit=YES;
programmatically
If you are using in xib than just click the check box "Scaling" scales Page to fit

- 2,710
- 4
- 24
- 27
This Logic for zooming of UIWebView, no need to add UIWebView on UIScrollView
Well only problem with webView.scalesPageToFit = YES;
is that, it will change initial content of font size but I found other option
Add <UIWebViewDelegate, UIScrollViewDelegate>
to your .h file
Creation of your UIWebView.
self.mWebview = [[UIWebView alloc] init];
self.mWebview.delegate = self; /// set delegate method of UIWebView
self.mWebview.frame = CGRectMake(0, 35, self.view.bounds.size.width, self.view.bounds.size.height - 80); // set frame whatever you want..
[self.mWebview setOpaque:NO];
self.mWebview.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.mWebview];
With load HTML file/content.
NSString* htmlString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"File Name"ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
[self.mWebview loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
#pragma mark -
#pragma mark - Webview Delegate Methods
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
webView.scrollView.delegate = self; // set delegate method of UISrollView
webView.scrollView.maximumZoomScale = 20; // set as you want.
webView.scrollView.minimumZoomScale = 1; // set as you want.
//// Below two line is for iOS 6, If your app only supported iOS 7 then no need to write this.
webView.scrollView.zoomScale = 2;
webView.scrollView.zoomScale = 1;
}
#pragma mark -
#pragma mark - UIScrollView Delegate Methods
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
self.mWebview.scrollView.maximumZoomScale = 20; // set similar to previous.
}
NOTE: I had to tested on Mac OS X - 10.9.3 with Xcode 5.1.1 and iOS version 6.1 and latter.
I hope this will helpful for you. :)

- 46,010
- 16
- 115
- 137
-
1The scrollViewDidEndZooming wasn't needed for me to get zooming working correctly. Not sure what the intent of that code is as it just is resetting the same value that was set earlier to the exact same value! – Norman H Apr 06 '15 at 20:46
-
1Ya exactly, why is the scrollViewDidEndZooming part needed at all? But other than that, superb answer. It made even those pages zoom which were not getting zoomed by just setting the "Scales page to fit" property. – GKK Nov 02 '16 at 09:41
I know this question is pretty old, but for everyone that is using a storyboard and prefers a visual answer here it is. Just check this box in the WebView's Attributes Inspector:

- 4,068
- 4
- 32
- 47
You MUST set scalesPageToFit=YES for any pinching and zooming to work on a UIWebView. It work for me.

- 1,196
- 1
- 18
- 31