在导航栏中为嵌入式 UISearchbar 设置色调颜色 [英] Setting tint color for embedded UISearchbar in Navigation bar

查看:25
本文介绍了在导航栏中为嵌入式 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 设置色调颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆