【问题标题】:UISearchController change colorUISearchController 改变颜色
【发布时间】:2021-07-02 05:16:38
【问题描述】:

我使用此代码更改我将其放入 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

【问题讨论】:

  • 你签入viewController了吗,你没有给self.navigation上色?

标签: ios swift uinavigationcontroller uisearchcontroller


【解决方案1】:

我找到了解决方案。我输入了 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-04
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 2015-06-04
    • 2014-05-06
    • 2012-10-04
    相关资源
    最近更新 更多