gpt4 book ai didi

ios - 为什么导航栏背景颜色没有改变?

转载 作者:行者123 更新时间:2023-12-01 15:44:14 24 4
gpt4 key购买 nike

当用户选择不同的主题样式时,我需要更改导航栏背景颜色。
但奇怪的是,当用户选择“Dark”模式后,进入backgorund,然后回到前台,如果用户想改回“Light”模式,导航栏还是黑色的,有一个“_UIVisualEffectBackdropView”保持黑暗。
但是如果用户在进入后台之前选择“Light”模式,那么一切正常。
我该如何修复这个错误?下面是代码和图片:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
self.changeToLightColor()
default:
self.changeToDarkColor()
}
}

private func changeToLightColor() {
self.navigationController?.navigationBar.barStyle = .default

let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemBlue]
self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}

private func changeToDarkColor() {
self.navigationController?.navigationBar.barStyle = .black

let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemGreen]
self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}
enter image description here
非常感谢您的帮助和提前回答!

最佳答案

嗯,花了一点时间来弄清楚如何解决这个问题,解决方案非常简单。
刚设置barTintColornavigationBar给你需要的颜色。

private func changeToLightColor() {
self.navigationController?.navigationBar.barStyle = .default

//Set to white color
self.navigationController?.navigationBar.barTintColor = UIColor.white

let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemBlue]
self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}

private func changeToDarkColor() {
self.navigationController?.navigationBar.barStyle = .black

//Set to black color
self.navigationController?.navigationBar.barTintColor = UIColor.black

let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemGreen]
self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}
我做了之后,问题就解决了

关于ios - 为什么导航栏背景颜色没有改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62862111/

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