【发布时间】:2021-11-22 09:43:00
【问题描述】:
我有一个自定义颜色主题的应用,主题可以在TableView Header标签和导航栏中实现颜色。
执行此操作时,它在 iOS14 上运行良好。但是随着 iOS15 的变化,导航栏不能再改变颜色了。在 iOS15 中处理了透明和 scrollEdgeAppearance,但是在应用程序运行时(在调用 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()
}
提前感谢您的帮助。
【问题讨论】: