Enable zooming/pinch on UIWebView

PdfUiwebview

Pdf Problem Overview


I have an UIWebView with a pdf-file. It works fine. But how can i enable zooming on the pdf-file?

Pdf Solutions


Solution 1 - Pdf

Make sure you checked "Scales page to fit"

Solution 2 - Pdf

you can use webView.scalesPageToFit=YES; programmatically

If you are using in xib than just click the check box "Scaling" scales Page to fit

Solution 3 - Pdf

> 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. :)

Solution 4 - Pdf

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:

enter image description here

Solution 5 - Pdf

If you want do by programmatically then use

webView.scalesPageToFit = true; 

If you are using storyboard then you have to tick check box "Scaling" scales Page to fit enter image description here

Solution 6 - Pdf

You MUST set scalesPageToFit=YES for any pinching and zooming to work on a UIWebView. It work for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavidView Question on Stackoverflow
Solution 1 - PdfJEzuView Answer on Stackoverflow
Solution 2 - PdfNithinbemitkView Answer on Stackoverflow
Solution 3 - PdfiPatelView Answer on Stackoverflow
Solution 4 - PdfScooterView Answer on Stackoverflow
Solution 5 - PdfAshuView Answer on Stackoverflow
Solution 6 - PdfSargisView Answer on Stackoverflow