iOS13更改状态栏背景颜色

2024-04-16

在 iOS13 中,我无法再更改状态栏的背景颜色,因为无法再使用“键的值”访问状态栏。 有人知道这是怎么可能的吗?或者是否知道这将在 iOS13 的最终版本中实现?

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

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

我希望状态栏能够获得我需要的背景颜色。


使用 UIStatusBarManager 的 Objective-C 版本:

UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame] ;
statusBar.backgroundColor = [UIColor whiteColor];
[[UIApplication sharedApplication].keyWindow addSubview:statusBar]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iOS13更改状态栏背景颜色 的相关文章

随机推荐