gpt4 book ai didi

ios - 从应用程序调用时更改状态栏的颜色

转载 作者:行者123 更新时间:2023-12-01 22:19:52 25 4
gpt4 key购买 nike

我正在设置导航栏和状态栏。

static func setParamsBars(){
let bounds = UIScreen.main.bounds

UIApplication.shared.statusBarView?.backgroundColor = .clear

UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName: UIFont(name: "SFUIDisplay-Regular", size: 18)!]

let imagebar : UIImage = UIImage(color: UIColor(red: 136.0/255.0, green: 136.0/255.0, blue: 136.0/255.0, alpha: 0.8), size: CGSize(width: bounds.size.width, height: 84))!
UINavigationBar.appearance().setBackgroundImage(imagebar, for: .default)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().isTranslucent = true
}

并在 didFinishLaunchingWithOptions中调用此函数

我的第一个屏幕 enter image description here

我打了电话 enter image description here

然后,当我返回到应用程序时,状态栏会更改颜色
enter image description here

然后,我添加了以下代码。保证:
func applicationDidBecomeActive(_ application: UIApplication) {
AppEventsLogger.activate(application)

print("applicationDidBecomeActive")
//AppDelegate.setParamsBars()
//UINavigationBar.appearance().clipsToBounds = false
//UINavigationBar.appearance().isTranslucent = true

UIApplication.shared.statusBarView?.backgroundColor = .clear

}

最佳答案

尝试如下扩展UIApplication:

(并且您可以使用每个ViewController进行更改)

override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

关于ios - 从应用程序调用时更改状态栏的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45563154/

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