【问题标题】:iOS: How to remove the grey bar on the sides?iOS:如何删除侧面的灰色条?
【发布时间】:2019-02-22 11:10:01
【问题描述】:

我想删除侧面的灰色条,但我不知道该怎么做。 我尝试了许多解决方案,例如:

 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))

但没有任何效果...

编辑:换成白色更好,但我想要一个真正的全屏 web 视图。

【问题讨论】:

  • 试试这个:webView.contentMode = .aspectFill
  • 你能添加你的 webview http URL

标签: ios webview view uiwebview cgrect


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      试试,

      webview.backgroundColor = .white
      

      【讨论】:

      • 问题是它只是改变颜色,我在我的问题中举了一个例子。
      • @ΩlostA 添加您的 URL,以便我们检查问题。我认为您正在 iPhone X 上进行横向模式测试。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 2017-10-16
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      相关资源
      最近更新 更多