space on iPhone X 如何设置状态栏或安全区域去掉白色?

How do you set the status bar or safe area to remove white space on iPhone X?

我已经添加了使用安全区域指南的选项,但当我查看该应用程序时,它似乎尊重安全区域,但有一些我无法摆脱的白色 space。我不知道是什么原因造成的,也不知道如何将颜色从白色更改。

我已经将背景颜色设置为您在下面看到的颜色。

view.backgroundColor = UIColor(red:0.227, green:0.251, blue:0.294, alpha:1)

我也设置了白色状态栏样式

UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

我的主要故事板

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
        }

SafeAreaGuide

if #available(iOS 11.0, *) {
     webView.scrollView.contentInsetAdjustmentBehavior = .never;
}