开发者

UIWebView's zoom range is very limited

I have a test UIWebView. I loaded a small amount of custom HTML into it. Nothing special -- two pages, a little text, and a sma开发者_如何学编程ll 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?


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


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜