gpt4 book ai didi

ios - UINavigationBar 标题颜色

转载 作者:行者123 更新时间:2023-11-28 21:01:48 25 4
gpt4 key购买 nike

为什么当我回到主 UIViewController 时,navigationBar 标题没有将其颜色更改为白色?这是简单的代码(viewWillAppearviewWillDisappear),但它不起作用,当我回到这个 VC 上时,标题保持绿色。应用中的主色也是绿色:

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.statusBarStyle = .lightContent

DispatchQueue.main.async {
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont(name: "Gotham-Medium", size: 20)!]
}
}


override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.shared.statusBarStyle = .default

navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.green, NSAttributedStringKey.font: UIFont(name: "Gotham-Medium", size: 20)!]


}

最佳答案

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.statusBarStyle = .lightContent

DispatchQueue.main.async {
addTitleLabel()
}
}


override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.shared.statusBarStyle = .default
}

func addTitleLabel(){
var titleLabel: UILabel = UILabel()
titleLabel.textColor = .white
titleLabel.textAlignment = .center
titleLabel.text = "Home"

self.navigationItem.titleView = titleLabel
}

从 viewWillAppear 调用此方法。

关于ios - UINavigationBar 标题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48243361/

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