在 iOS13 中更改状态栏背景颜色 [英] Change status bar background color in iOS13

查看:82
本文介绍了在 iOS13 中更改状态栏背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iOS13 中,我无法再更改状态栏的背景颜色,因为无法再使用键值"访问状态栏.有没有人知道这是怎么可能的,或者有没有人知道在 iOS13 的最终版本中是可能的?

With iOS13 I cannot change the background color of the statusbar anymore because the statusbar is no longer accessible using "value for key". Did anybody figure out how this is possible or is there any knowledge that it will be possible in the final version of iOS13?

我遇到了不同的建议,比如使用 UIApplications StatusBarView(在 xcode 11、beta 7 中不再可用)或使用 statusbarmanager.两者都不允许访问状态栏.

I came across different proposals already like using the UIApplications StatusBarView (no longer accessible in xcode 11, beta 7) or using the statusbarmanager. Both do not give access to the status bar.

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to: #selector(setter: UIView.backgroundColor)) {
  statusBar.backgroundColor = <Some Color>
}

我希望状态栏获得我需要的背景颜色.

I expect the status bar to get the background color that I need.

推荐答案

Objective-C Version using UIStatusBarManager:

Objective-C Version using UIStatusBarManager:

UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame] ;
statusBar.backgroundColor = [UIColor whiteColor];
[[UIApplication sharedApplication].keyWindow addSubview:statusBar]

这篇关于在 iOS13 中更改状态栏背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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