Setting tint color for embedded UISearchbar in Navigation bar(在导航栏中为嵌入式 UISearchbar 设置色调颜色)
问题描述
我有一个应用程序,整个 UI 都带有蓝色主题.我在初始视图的导航栏中也有一个嵌入式搜索栏.我的应用程序按钮文本颜色为白色,并在应用程序委托中声明:
I have an app that has a blue tint theme to the entire UI. I also have an embedded search bar in the Navigation Bar on my initial view. My button text color for the app is white and declare that in the app delegate using:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
问题是这会导致嵌入式搜索栏在选择光标时隐藏光标,因为白色色调会影响搜索栏.我尝试使用两种方法专门将搜索栏的色调设置为 [UIColor blueColor],但没有运气.我尝试引用 UISearch 栏的两种方法是:
Problem is that this causes the embedded search bar to hide the cursor when it is selected because of the white tint affecting the search bar. I have tried to specifically set the tint of the search bar to [UIColor blueColor] using two methods but have had no luck. The two ways I have tried to refrence the UISearch bar are:
[self.navigationController.searchDisplayController.searchBar setTintColor:[UIColor blueColor]];
和
[searchBar setTintColor:[UIColor blueColor]]
应该正确引用searchBar.
The searchBar should be referenced properly.
我对这些网点所做的一切都不会影响嵌入式搜索栏.
Nothing I do to these outlets affect the embedded search bar at all.
推荐答案
遇到了同样的问题.将搜索栏嵌入导航栏后使用此代码解决.
Had the same problem. Solved it by using this code after embedding the search bar into navigation bar.
self.navigationItem.titleView.tintColor = [UIColor blueColor];
可能不是最好的解决方案,但它确实有效.
Probably not the best solution, but it works.
这篇关于在导航栏中为嵌入式 UISearchbar 设置色调颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在导航栏中为嵌入式 UISearchbar 设置色调颜色
基础教程推荐
- 更改 UITableView 部分标题的颜色 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01