首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UISearchController更改颜色

UISearchController更改颜色
EN

Stack Overflow用户
提问于 2021-04-06 20:07:28
回答 1查看 20关注 0票数 0

我使用以下代码来更改我放在AppDelegate中的导航栏外观:

代码语言:javascript
复制
UINavigationBar.appearance().barTintColor = UIColor(hex: "E1354A")
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
UINavigationBar.appearance().isTranslucent = false

我还使用了UISearchController,它是我以编程方式添加的。但是当我按下它的时候,导航栏和搜索控制器的颜色就变成了黑色。我不明白为什么会发生这种情况,我怎么才能防止它呢?

[

][1

EN

回答 1

Stack Overflow用户

发布于 2021-04-06 20:21:29

我找到了一个解决方案。我放入了viewDidLoad:

代码语言:javascript
复制
   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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66968351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档