UIWebView set initial zoom scale programmatically when loading an external website?(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.
meta 设置方法看起来很有希望——但是当我不控制将要加载的 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.
如果您将此设置为是",则网页会缩放以适应用户,并且用户可以放大和缩小.如果否,则禁用用户缩放.默认值为 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 在加载外部网站时以编程方式设置初始缩放比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIWebView 在加载外部网站时以编程方式设置初始缩放比例?
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01