我尝试通过以下方式为UIWebview设置最大缩放比例:
webView.scrollView.maximumZoomScale=2.0;
webView.scrollView.minimumZoomScale=1.0;
但是现在无法做到。如果有任何人有想法,请告诉我们。
我尝试通过以下方式为UIWebview设置最大缩放比例:
webView.scrollView.maximumZoomScale=2.0;
webView.scrollView.minimumZoomScale=1.0;
按照以下步骤:
1)添加静态const float zoomSc = 3.0
; 同时在.h
文件中添加UIScrollViewDelegate
2)yourWebView.scrollView.delegate = self
;
3)添加下面的scrollView代理方法
- (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()"];
}