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 设置色调颜色
基础教程推荐
- 如何使 UINavigationBar 背景透明? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
