我使用以下代码来更改我放在AppDelegate中的导航栏外观:
UINavigationBar.appearance().barTintColor = UIColor(hex: "E1354A")
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
UINavigationBar.appearance().isTranslucent = false我还使用了UISearchController,它是我以编程方式添加的。但是当我按下它的时候,导航栏和搜索控制器的颜色就变成了黑色。我不明白为什么会发生这种情况,我怎么才能防止它呢?
[

][1

发布于 2021-04-06 20:21:29
我找到了一个解决方案。我放入了viewDidLoad:
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = UIColor(hex: "E1354A")
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
navigationItem.standardAppearance = appearance
navigationItem.scrollEdgeAppearance = appearance
let searchField = searchController.searchBar.searchTextField
searchField.backgroundColor = .systemBackgroundhttps://stackoverflow.com/questions/66968351
复制相似问题