【发布时间】:2020-11-01 20:06:14
【问题描述】:
当用户选择不同的 Theme 样式时,我需要更改 navigationBar 背景颜色。
但奇怪的是,当用户选择“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
}
非常感谢您的帮助和提前回答!
【问题讨论】:
标签: ios swift uinavigationcontroller uinavigationbar ios13