加载外部网站时,UIWebView以编程方式设置初始缩放比例? [英] UIWebView set initial zoom scale programmatically when loading an external website?

查看:191
本文介绍了加载外部网站时,UIWebView以编程方式设置初始缩放比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是为外部网站设置初始缩放比例[在某些情况下,内容偏移,但这不太重要]。但是在应用程序最初设置缩放和偏移后,用户应该能够更改它们,并且应用程序不应该干扰。

What I want to do is set the initial zoom scale [and in some cases, content offset, but that is less important] for an external website. But after the app initially sets the zoom and offset, the user should be able to change them, and the app should not interfere.

可以获得一些相关信息这里这里此处。但据我所知,没有一个能做我想要的。

Some related information is available here, here, and here. But as far as I can tell, none of does what I want.

元设置方法看起来很有希望 - 但是当我不控制将要加载的html内容时,如何设置它?

The meta setting approach looks promising -- but how would I set it when I don't control the html content that will be loaded?

推荐答案

尝试此设置初始缩放级别 -

Try this for setting the initial zoom level -

[webView stringByEvaluatingJavaScriptFromString:@"document. body.style.zoom = 5.0;"];

也不要忘记将 scalesPageToFit 设置为NO你已经完成了。

Also dont forget to set scalesPageToFit to NO and you're done.


如果你把它设置为YES,那么网页会缩放以适应,用户可以放大和缩小。如果为NO,则禁用用户缩放。默认值为NO。

If you set this to YES, the webpage is scaled to fit and the user can zoom in and zoom out. If NO, user zooming is disabled. The default value is NO.

这篇关于加载外部网站时,UIWebView以编程方式设置初始缩放比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆