iOS: 如何去掉边上的灰条?

iOS: How to remove the grey bar on the sides?

我想去掉边上的灰色条,但我不知道该怎么做。 我尝试了很多解决方案,例如:

 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.backgroundColor = .white

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

width:100%; height:100%; background-size:cover;

您正在使用 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"