Allowing user to pinch zoom in/out of a webview

Viewed 22657

I have a WebView into which I'm loading a local HTML page with some embedded images. I want to allow the user to zoom in on the text and image in a similar fashion as they would with the web browser.

Any ideas how to enable this?

Thanks

4 Answers

This is the code that works for me:

// declare and allocate UIWebView before
// UIWebView *webView;
// webView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, w, h)];
webView.scalesPageToFit = YES;

For completeness. You must enable multitouch, scalesPagesToFit to get it to work (there are some conditions if its within certain other views).

But then to prevent it scaling your webpage (especially if using local files). You will need to add the following snippet to your HTML

For more info so: http://iphoneincubator.com/blog/windows-views/right-scale-for-a-uiwebview

Related