如何为ios 11设置不安全的区域背景颜色 [英] How to set unsafe area background color for ios 11

查看:1856
本文介绍了如何为ios 11设置不安全的区域背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用xcode 9创建一些新的视图控制器,所以现在我有几个安全区域可以处理。

Creating some new view controllers with xcode 9 so now I have a few safe areas to deal with.

我目前正在尝试做一些全面的事情,这意味着保持不安全的区域(因为我总是显示状态栏)并且背景颜色延伸到全屏(以保持与我以前相似的行为)。

I am currently trying to do something fullproof, meaning keeping the unsafe area as it is (since I always display the status bar) and having the background color extending to the fullscreen (to keep a similar behaviour to what I used to have).

另外请注意,这也会影响页面控件,因为当你有一些时,系统会把它们放在底部的不安全区域,这个区域也会以黑色显示。

On an additional note, this also affect page controls since when you have some the system will put them in the bottom unsafe area which will also be displayed in black.

我找不到让背景颜色延伸到不安全区域后面的方法。
有什么想法吗?

I cannot find a way for the background color to extend behind the unsafe area though. Any thoughts?

推荐答案

它看起来像一个hacky技巧但你可以试试这个:

您可以在应用程序启动期间或视图控制器的viewDidLoad期间为状态栏设置背景颜色。这对我有用,方法如下。

It looks like a hacky trick but you may try this:
You can set background color for status bar during application launch or during viewDidLoad of your view controller. Here it works for me, in following ways.

extension UIApplication {

    var statusBarView: UIView? {
        return value(forKey: "statusBar") as? UIView
    }

}


or 
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        UIApplication.shared.statusBarView?.backgroundColor = UIColor.green
    }

}


// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        UIApplication.shared.statusBarView?.backgroundColor = UIColor.green
        return true
    }
}




结果如下:



Here is result:

这篇关于如何为ios 11设置不安全的区域背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆