ios - 如何设置状态栏或安全区域以去除 iPhone X 上的空白?

标签 ios swift ios11 iphone-x safearealayoutguide

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

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

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

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

UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

enter image description here

我的主要 Storyboard

enter image description here

enter image description here enter image description here

最佳答案

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,因此您的对象不会裁剪。 enter image description here

以编程方式作为:

 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

关于ios - 如何设置状态栏或安全区域以去除 iPhone X 上的空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47144589/

相关文章:

ios - 当应用程序已打开时,Segue 不执行快速操作(Xcode 9)

mapkit - MKMarkerAnnotationView 簇颜色

ios - 如何在保持单元格选择的同时向 UICollectionView 添加点击手势?

ios - 从频域到时域

ios - 以编程方式创建按钮以转到下一个 View 时如何在 View 中传递数据?

ios - 创建一个 segue 并通过 Swift 将其附加在两个 View Controller 之间?

ios - UILabel文本换行问题

Swift:Force Unwrapped 返回 nil 而不会崩溃

ios - 图片.xcassets : error: Failed to find a suitable device for the type SimDeviceType

ios - 当我们在 ios 中点击它时如何更改 UIbuttons 文本颜色