【问题标题】:How to set the UISearchBar cancel button highlight color如何设置 UISearchBar 取消按钮高亮颜色
【发布时间】:2014-10-23 20:43:35
【问题描述】:

我有一个 UISearchBar,它在 xib 文件中添加到我的视图控制器中。

我通过 Interface Builder 设置了以下属性:

barStyle = UIBarStyleDefault
searchBarStyle = UISearchBarStyleMinimal
translucent = YES
barTintColor = Clear Color

在代码中,我使用此代码对栏进行样式设置,以使文本颜色为白色:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

在我的应用程序委托中,我有 didFinishLoading 方法:

 self.window.tintColor = [UIColor whiteColor];

我在 UISearchBar 中的取消按钮是浅灰色的。当我选择它时,它会突出显示蓝色,这很刺耳,因为它不适合屏幕中的任何其他视觉元素。如何更改按钮以突出显示为不同的颜色?或者,如果取消按钮是白色并突出显示为灰色,我会很好,就像我的导航栏按钮一样,但我不知道如何更改按钮颜色。

我的目标是 iOS7,使用 Xcode 5。


这个答案似乎很合适,但对我没有影响https://stackoverflow.com/a/15791136/472344

【问题讨论】:

    标签: ios ios7 uisearchbar


    【解决方案1】:

    在didFinishLaunchingWithOptions的Appdelegate中试试这个

    [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],UITextAttributeTextShadowOffset,nil] forState:UIControlStateNormal];
    

    【讨论】:

      【解决方案2】:

      尝试设置搜索栏的 tintColor。它适用于目标 8.0 xcode 5。

      self.searchBar.tintColor = [UIColor blackColor];

      【讨论】:

        猜你喜欢
        • 2011-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-21
        • 1970-01-01
        相关资源
        最近更新 更多