iOS 网页视图缩放级别
iOS Webview Zoom Level
如何以编程方式找到 webview's
scrollView
的缩放级别。我尝试使用以下代码。
我的代码:
[WebView stringByEvaluatingJavaScriptFromString:[Nssting stringWithFormat:@"document.body.style.zoom = %f;",zoomlevel];
获取 webView
的 scrolView
,然后使用以下代码对其应用一些操作。您可以通过以下方式申请。
检测您的内容大小并设置缩放级别:
UIScrollView *sview = [[webview subviews] objectAtIndex:0];
[self.webView.scrollView setZoomScale:1.5 animated:YES];
还有一些:
for (UIView *subView in [self.view subviews]) {
if ([subView isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subView;
[scrollView setZoomScale:2.5f animated:YES];
}
}
注:内部scrollview
是webview
的subview
。
编辑:
只需使用 webview
的委托方法即可获取高度和宽度,请参见以下代码:
- (void)webViewDidFinishLoad:(UIWebView *)aWebView
{
CGFloat height = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
CGFloat width = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
CGRect frame = aWebView.frame;
frame.size.height = height;
frame.size.width = width;
aWebView.frame = frame;
}
终于找到答案了
可能对任何人都有帮助。
这是我的回答:
将此元标记添加到您的 html 字符串中。
元名称='viewport'内容='width=300,minimum-scale=0.25,maximum-scale=3.0,user-scalable=yes'
谢谢,
AKS
如何以编程方式找到 webview's
scrollView
的缩放级别。我尝试使用以下代码。
我的代码:
[WebView stringByEvaluatingJavaScriptFromString:[Nssting stringWithFormat:@"document.body.style.zoom = %f;",zoomlevel];
获取 webView
的 scrolView
,然后使用以下代码对其应用一些操作。您可以通过以下方式申请。
检测您的内容大小并设置缩放级别:
UIScrollView *sview = [[webview subviews] objectAtIndex:0];
[self.webView.scrollView setZoomScale:1.5 animated:YES];
还有一些:
for (UIView *subView in [self.view subviews]) {
if ([subView isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subView;
[scrollView setZoomScale:2.5f animated:YES];
}
}
注:内部scrollview
是webview
的subview
。
编辑:
只需使用 webview
的委托方法即可获取高度和宽度,请参见以下代码:
- (void)webViewDidFinishLoad:(UIWebView *)aWebView
{
CGFloat height = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
CGFloat width = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
CGRect frame = aWebView.frame;
frame.size.height = height;
frame.size.width = width;
aWebView.frame = frame;
}
终于找到答案了
可能对任何人都有帮助。
这是我的回答:
将此元标记添加到您的 html 字符串中。
元名称='viewport'内容='width=300,minimum-scale=0.25,maximum-scale=3.0,user-scalable=yes'
谢谢, AKS