我正在尝试将 UIWebView 内容缩放到模拟器的屏幕上。但是,我无法弄清楚如何将内容扩展到相应的 IOS 设备。我尝试了多种方法来更改内容的缩放比例,但在其他页面上找不到任何内容。我也没有在这个项目中使用 Storyboard。我正在使用直接代码来对应用程序进行约束。这是 UIWebView 的代码
func handleDownload() {
//print(123)
let webView = UIWebView (frame: view.frame)
webView.backgroundColor = UIColor.redColor()
view.addSubview(webView)
webView.loadRequest(NSURLRequest(URL: NSURL(string: "https://storage.com")!))
}
我尝试过使用此代码:
func zoomToFit() {
if theWebView.respondsToSelector(#selector(self.scrollView)) {
var scrollView: UIScrollView = theWebView.scrollView()
var zoom: Float = theWebView.bounds.size.width / scrollView.contentSize.width
scrollView.minimumZoomScale = zoom
scrollView.setZoomScale(zoom, animated: true)
}
}
这似乎不起作用..
谢谢!
最佳答案
我搜索了这个,发现你应该在 HTML 中将其设置为可缩放。像这样:
<meta name="viewport" content="user-scalable=yes, width=device-width" />
您应该将其scalesPageToFit 设置为false。像这样:
webView.scalesPageToFit = false
关于ios - 快速缩放 UIwebview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38493636/