iOS:如何删除两侧的灰色条?

问题描述 投票:1回答:3

我想删除侧灰条但我不知道该怎么做。我试过很多解决方案,比如

enter image description here

 self.webView.frame = self.view.bounds
 self.webView.scalesPageToFit = true
 webView = UIWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))

但没有任何作用......

编辑:改变白色更好,但我想有一个真正的全屏webview。 enter image description here

ios webview view uiwebview cgrect
3个回答
2
投票

您正在使用iPhone X(或类似)测试您的项目,iPhone X具有顶部和底部安全区域边距(在这种情况下为左右边距,因为您在横向模式下使用它)。

您可以使用AutoLayout引擎来设置视图布局,执行以下操作:

NSLayoutConstraint.activate([
    self.webView.topAnchor.constraint(equalTo: self.view.topAnchor),
    self.webView.rightAnchor.constraint(equalTo: self.view.rightAnchor),
    self.webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
    self.webView.leftAnchor.constraint(equalTo: self.view.leftAnchor)
]);

Reference to Apple documentation about: "Adaptivity and Layout"


1
投票

尝试,

webview.backgroundColor = .white

1
投票

您可以更改页面的CSS以适应网页的100%宽度和100%高度。

width:100%; height:100%; background-size:cover;
© www.soinside.com 2019 - 2024. All rights reserved.