我想删除侧灰条但我不知道该怎么做。我试过很多解决方案,比如
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))
但没有任何作用......
您正在使用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"
尝试,
webview.backgroundColor = .white
您可以更改页面的CSS以适应网页的100%宽度和100%高度。
width:100%; height:100%; background-size:cover;