我尝试通过以下方式为 UIWebview 设置最大缩放比例
webView.scrollView.maximumZoomScale=2.0;
webView.scrollView.minimumZoomScale=1.0;
但做不到。如果有人有任何想法,请告诉..
最佳答案
按照以下步骤:
1) 添加静态const float zoomSc = 3.0
;同时在.h
文件中添加UIScrollViewDelegate
2) 你的WebView.scrollView.delegate = self
;
3) 在scrollView委托(delegate)方法下方添加
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
if (scale > zoomSc)
{
scrollView.zoomScale= zoomSc;
}
}
编辑:更改缩放系数
的范围
在 UIWebViewDelegate 的
方法中添加以下内容。
注意:不要忘记为 UIWebView
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//restrict zoomscale by adding javascript code
//make changes to only maximum-scale value as i have set it to 10.0.
NSString *strJSFunction = [NSString stringWithFormat:@"function increaseMaxZoomFactor(){ var element = document.createElement('meta'); element.name = \"viewport\"; element.content = \"maximum-scale=10.0\"; var head = document.getElementsByTagName('head')[0]; head.appendChild(element); }"];
[webView stringByEvaluatingJavaScriptFromString:strJSFunction];
[webView stringByEvaluatingJavaScriptFromString:@"increaseMaxZoomFactor()"];
}
关于iphone - 为 UIWebView 设置最大缩放比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11125205/