2

How to get zoom in UIWebView.

I loaded pdf file from resource bundle in a UIWebView.

Now trying to zoom the webview. so its will get zooming effect to the pdf file.

So.

How can i zoom the UIWebView.

Any sample example. Please help me out.

USER
  • 21
  • 1
  • 5

3 Answers3

5

Just use the following code:

self.pdfviewwebview.scalesPageToFit = YES;
self.pdfviewwebview.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.pdfviewwebview.delegate = self;

The most tricky thing here which most people forget is to set the webview's delegate,so take care about that.

Shantanu
  • 3,086
  • 3
  • 25
  • 32
2
UIWebView *tempWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];  
tempWebView.backgroundColor = [UIColor whiteColor];  
**tempWebView.scalesPageToFit = YES; //this enables the zooming**
tempWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
tempWebView.delegate = self;
[self.view addSubview:tempWebView]; 
[self setWebView:tempWebView];


NSString *path = [[NSBundle mainBundle] pathForResource:@"your_file" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.webView loadRequest:request];
Kristian Glass
  • 37,325
  • 7
  • 45
  • 73
sheisd
  • 179
  • 1
  • 10
-1

A pinch-to-zoom gesture can be simulated by holding down the Option key. On your simulator, two grey circles will appear indicating that its simulating a multi-touch, pinch-to-zoom gesture.

BearDroid
  • 553
  • 1
  • 6
  • 16
  • 1
    Its pinch to zoom ... i made webview.delegate=self; and webview.scalesPageToFit=YES; webView.multipleTouchEnabled=YES; and added it into view self.view addsubview this have done but ... zooming function is not working. – USER Jul 20 '11 at 09:33