1) webView初始化时设置属性
UIWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, IphoneWidth, IphoneHeight - 64)];
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
webView.scalesPageToFit = YES;
webView.multipleTouchEnabled = YES;
webView.userInteractionEnabled = YES;
webView.scrollView.scrollEnabled = YES;
webView.contentMode = UIViewContentModeScaleAspectFit;
webView.delegate = self;
self.webView = webView;
2) 如果设置了上述的属性网页依旧不可以缩放,则在UIWebView代理方法中添加:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *jsMeta = [NSString stringWithFormat:@"var meta = document.createElement('meta');meta.content='width=device-width,initial-scale=1.0,minimum-scale=.5,maximum-scale=3';meta.name='viewport';document.getElementsByTagName('head')[0].appendChild(meta);"];
[self.webView stringByEvaluatingJavaScriptFromString:jsMeta];
}