[英]Set Maximum Zoom Scale for UIWebView
我嘗試過為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;
}
}
編輯 :更改zoom factor
range
在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()"];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.