我有一个带有自定义颜色主题的应用,主题可以在 TableView 标题标签 和导航栏 中实现颜色。
执行此操作时,它在 iOS14 上运行良好。但是随着iOS15的变化,导航栏不能再变色了。透明和 scrollEdgeAppearance 已在 iOS15 中处理,但在应用程序运行时(在调用 application(didFinisLaunching) 之后)基于用户输入的 NavBar 当前颜色更改不起作用。
我使用以下代码在用户选择颜色时触发:
func setNavBarColour() {
if #available(iOS 15, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
appearance.backgroundColor = LangBuilds.flavColor
let proxy = UINavigationBar.appearance()
proxy.tintColor = LangBuilds.flavColor
proxy.standardAppearance = appearance
proxy.scrollEdgeAppearance = appearance
}
else {
self.navigationController?.navigationBar.barTintColor = LangBuilds.flavColor
}
self.searchController.searchBar.searchTextField.textColor = .black
self.searchController.searchBar.searchTextField.backgroundColor = .white
self.searchController.searchBar.searchTextField.autocapitalizationType = .none
changeTextHolder()
}
提前感谢您的帮助。
最佳答案
the NavBar current-colour change based on user input while the app is running(after application(didFinisLaunching) has been called) is not working
您不能使用 appearance
代理更改导航栏颜色而该导航栏正在显示。 appearance
代理仅影响 future 界面元素。您需要将 UINavigationBarAppearance 直接应用到现有的导航栏:
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = appearance
关于ios - 更改 iOS 15 中导航栏的当前颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69394073/