Reputation: 27365
I have a test UIWebView. I loaded a small amount of custom HTML into it. Nothing special -- two pages, a little text, and a small image on one of the pages. I am using it to test out the class.
One problem I am having is that my ability to zoom in and out is very limited. It seems that even if I set the minimumZoomScale and maximumZoomScale properties of the UIWebView's UIScrollView, something resets them to a factor of 1.5 or smaller ratio. And if I try to set them often, the app gets very unhappy and is prone to crash.
Can anyone explain what is going on?
Upvotes: 0
Views: 793
Reputation: 2806
I know about this JavaScript tag. But I didn't know how to implement this tag. After spend some time I got my solution.
Try below code. Change your minimum-scale
and maximum-scale
as per your requirement.
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString* js =
@"var meta = document.createElement('meta'); " \
"meta.setAttribute( 'name', 'viewport' ); " \
"meta.setAttribute( 'content', 'width = device-width, initial-scale = 1.0,minimum-scale=1.0,maximum-scale=10.0 user-scalable = yes' ); " \
"document.getElementsByTagName('head')[0].appendChild(meta)";
[webView stringByEvaluatingJavaScriptFromString: js];
}
Upvotes: 0
Reputation: 6082
You need to put the following line in the head
section of your HTML document.
<meta name="viewport" content="user-scalable=yes,maximum-scale=5.0,minimum-scale=0.25" />
Docs regarding this: http://developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariHTMLRef/Articles/MetaTags.html
Upvotes: 4