Mark
Mark

Reputation:

Allowing user to pinch zoom in/out of a webview

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

Upvotes: 20

Views: 22735

Answers (4)

Vladimir
Vladimir

Reputation: 170829

Try to set UIWebView property scalesPageToFit to YES

Upvotes: 54

Tomahawk PPC
Tomahawk PPC

Reputation: 162

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;

Upvotes: 5

Anthony Main
Anthony Main

Reputation: 6068

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

Upvotes: 5

Ben Call
Ben Call

Reputation: 976

I used scalesPageToFit to YES.... it allows it to zoom in some... but not a true zoom like safari has.

Upvotes: 4

Related Questions