我尝试按
设置UIWebview的最大缩放比例 webView.scrollView.maximumZoomScale=2.0;
webView.scrollView.minimumZoomScale=1.0;
但无法做到。如果有任何机构有任何想法请告诉..
答案 0 :(得分:1)
按照以下步骤操作:
1)添加静态const float zoomSc = 3.0
;另请在UIScrollViewDelegate
文件
.h
2)yourWebView.scrollView.delegate = self
;
3)在scrollView委托方法下面添加
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
if (scale > zoomSc)
{
scrollView.zoomScale= zoomSc;
}
}
编辑:更改range
zoom factor
在UIWebViewDelegate's
方法中添加以下内容。
注意:不要忘记为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()"];
}