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 设置色调颜色
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
