Sharanya K M
Sharanya K M

Reputation: 1805

how to add pinch and zoom on a uiwebview - iphone

I know this question has been asked a couple of times before. I m trying to zoom in / out the uiwebview. How exactly do i do this? I tried setting 'webView.scalesPageToFit=YES;' but its not working.

I also tried this How do I enable the zoom in/out option in a UIWebView? but yet im not able to achieve the zoom in / out

Code

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[actorUrlArray objectAtIndex:_rowNumberInActivity]]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
webView.scalesPageToFit=YES;

what am i missing out here?

NOTE : I'm loading the iphone app on the ipad to check the app. Can that be a problem??

If its the meta tag problem. how do i set them? i tried this code.. but its not working.. i know nothing about javascript.. so im not sure whether this is correct or not..

NSString* js = 
@"var meta = document.createElement('meta'); \" \"meta.setAttribute( 'name', 'viewport' ); \" \"meta.setAttribute( 'content', 'width = device-width, initial-scale = 5.0, user-scalable = yes' ); \" \"document.getElementsByTagName('head')[0].appendChild(meta)";

[webView stringByEvaluatingJavaScriptFromString: js];

Upvotes: 1

Views: 3015

Answers (2)

Vineesh TP
Vineesh TP

Reputation: 7963

just simply set the property.

scalesPageToFit=YES

for any pinching and zooming to work on a UIWebView

Upvotes: 4

Pritesh Acharya
Pritesh Acharya

Reputation: 1626

Zooming in and out and Pinch are built in feature of UIWebView. You don't need to write any code to achieve that.

Upvotes: 4

Related Questions