gpt4 book ai didi

ios - 如何更改第二个 UIWindow 的状态栏颜色?

转载 作者:行者123 更新时间:2023-11-29 05:23:27 25 4
gpt4 key购买 nike

我在我的应用程序中添加了第二个窗口,用于在用户点击远程推送通知时显示特定 Controller 。

func navigateThroughPushnotification(controller: UINavigationController) {
let window = UIWindow(frame: UIScreen.main.bounds)
let vc = UIViewController()
vc.view.backgroundColor = .clear
window.rootViewController = vc
window.windowLevel = UIWindow.Level.alert + 1
window.makeKeyAndVisible()
if let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView {
statusBar.backgroundColor = kAppDefaultColor
}
vc.present(controller, animated: true, completion: nil)
}

问题是我也想更改此窗口的状态栏颜色,但我用来更改主窗口颜色的代码这次不起作用。

guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return true }
statusBar.backgroundColor = kAppDefaultColor

现在这段代码对于主窗口来说效果很好。请有人帮助检测应该做什么来改变第二个窗口的颜色。提前致谢

最佳答案

仅适用于 iOS 7 及更高版本

首先转到应用程序的 Info.plist,将基于 View Controller 的状态栏外观设置为 YES。

在每个 View Controller 中覆盖preferredStatusBarStyle之后。

例如:

override var preferredStatusBarStyle: UIStatusBarStyle {     
return .lightContent
}

如果您有 preferredStatusBarStyle 根据 View Controller 内部发生的变化返回不同的首选状态栏样式,那么您需要在状态更改时调用 setNeedsStatusBarAppearanceUpdate() .

关于ios - 如何更改第二个 UIWindow 的状态栏颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58430020/

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