gpt4 book ai didi

ios - Swift:更改 iOS 13 的状态栏颜色

转载 作者:行者123 更新时间:2023-12-01 17:35:10 24 4
gpt4 key购买 nike

对于 ios 13,我无法设置状态栏的文本颜色。如何获取 statusBarManager 的 View ?如何仅更改文本颜色?

由于:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'

我当前的代码:

    func setStatusBarTextColor(_ color: UIColor) {
if #available(iOS 13.0, *) {
// How to do for iOS 13??
} else {
if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
statusBar.setValue(color, forKey: "foregroundColor")
}
}
}

我已经找到了这个https://stackoverflow.com/a/57394751/9172697但这不是我想要的

最佳答案

IOS 13.0 和 XCode 11.0 与 Swift 5.0 100% 工作

    if #available(iOS 13.0, *) {


let statusBar1 = UIView()
statusBar1.frame = UIApplication.shared.keyWindow?.windowScene?.statusBarManager!.statusBarFrame as! CGRect
statusBar1.backgroundColor = UIColor.black

UIApplication.shared.keyWindow?.addSubview(statusBar1)

} else {

let statusBar1: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar1.backgroundColor = UIColor.black
}

关于ios - Swift:更改 iOS 13 的状态栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57943692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com