gpt4 book ai didi

ios - 如何在应用程序运行时更改 NavigationBarColor

转载 作者:行者123 更新时间:2023-11-28 05:41:40 26 4
gpt4 key购买 nike

我用它在运行前设置 NavigationBarColor:

 UINavigationBar.appearance().barTintColor = Color.NavigationBackground

但是在程序中,我想改变NavigationBarColor,所以我又用了这个

 UINavigationBar.appearance().barTintColor = Color.Black

但什么也没发生,它仍然是白色的(Color.Background)
颜色是我定义的结构。
如何正确改变颜色?我想这样实现:Trying to reload view controller to update the current theme

最佳答案

如果您希望每个屏幕都具有不同的颜色,请在下方添加您在 View 中选择的颜色的行,并且它会为每个屏幕更改颜色。

swift 4.2:

//To change Navigation Bar Background Color
UINavigationBar.appearance().barTintColor = UIColor.blue
//To change Back button title & icon color
UINavigationBar.appearance().tintColor = UIColor.white
//To change Navigation Bar Title Color
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

add it in view 会出现,然后你可以看到它的变化。

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.barTintColor = .orange
}

关于ios - 如何在应用程序运行时更改 NavigationBarColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56524035/

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