UISearchController 改变颜色

问题描述

我使用此代码来更改我将其放在 AppDelegate 中的导航栏外观:

UINavigationBar.appearance().barTintColor = UIColor(hex: "E1354A")
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
UINavigationBar.appearance().isTranslucent = false

我还使用以编程方式添加的 UISearchController。但是当我按下它时,导航栏和搜索控制器的颜色变为黑色。我不明白为什么会发生这种情况以及如何预防?

[

enter image description here

][1

enter image description here

解决方法

我找到了解决办法。我放入 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 = .systemBackground

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...