我已经添加了使用安全区域准则的选项,但当我查看该应用程序时,它似乎尊重安全区域,但有一些我无法摆脱的空白。我不知道是什么原因造成的,也不知道如何将颜色从白色更改。
我已将背景颜色设置为您在下面看到的颜色。
view.backgroundColor = UIColor(red:0.227, green:0.251, blue:0.294, alpha:1)
我还设置了白色状态栏样式
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
我的主要 Storyboard
最佳答案
When the view is visible onscreen, this guide reflects the portion of the view that is not covered by navigation bars, tab bars, toolbars, and other ancestor views. (In tvOS, the safe area reflects the area not covered the screen's bezel.) If the view is not currently installed in a view hierarchy, or is not yet visible onscreen, the layout guide edges are equal to the edges of the view.
需要用safeArea设置约束
使用 safeArea
设置 webView
的顶部、底部、前导、尾随约束
常量为 0,因此您的对象不会裁剪。
以编程方式作为:
webView.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
let guide = self.view.safeAreaLayoutGuide
webView.trailingAnchor.constraint(equalTo: guide.trailingAnchor).isActive = true
webView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: guide.bottomAnchor).isActive = true
webView.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true
}
关于ios - 如何设置状态栏或安全区域以去除 iPhone X 上的空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47144589/