gpt4 book ai didi

ios - NavigationBar 改变颜色本身

转载 作者:行者123 更新时间:2023-11-28 15:05:43 29 4
gpt4 key购买 nike

我有 2 个 VC。在这两种情况下,我都将代码编写为 NavigationController 外观,但是当我从第二个 VC 返回到第一个时,我的一切都是黑色的......

第一位风投:

override func viewDidLoad() {
super.viewDidLoad()

self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.barTintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.tintColor = UIColor.init(red:47/255.0, green:158/255.0, blue:249/255.0, alpha: 1.0)
}

第二个风投:

self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.barTintColor = UIColor.black
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
self.navigationController?.navigationBar.tintColor = UIColor.white

那么为什么当我回到第一个 VC 时它不从 viewDidLoad 加载颜色?

enter image description here

最佳答案

因为您的第一个 ViewController 已经加载,所以将您的导航栏设置放在 viewWillAppear

override func viewWillAppear() {
super. viewWillAppear()

self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.barTintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.tintColor = UIColor.init(red:47/255.0, green:158/255.0, blue:249/255.0, alpha: 1.0)
}

关于ios - NavigationBar 改变颜色本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48490691/

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