繁体   English   中英

如何设置UISearchBar取消按钮突出显示颜色

[英]How to set the UISearchBar cancel button highlight color

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

我通过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中的我的取消按钮是浅灰色。 当我选择它时,它会突出显示蓝色,这很刺眼,因为它与屏幕上的任何其他视觉元素都不匹配。 如何更改按钮以突出显示为其他颜色? 另外,如果取消按钮是白色的并且像导航栏按钮一样突出显示为灰色,我会没事的,但是我不知道如何更改按钮的颜色。

我使用Xcode 5定位iOS7。


这个答案似乎合适,但对我没有任何效果https://stackoverflow.com/a/15791136/472344

在didFinishLaunchingWithOptions中的Appdelegate中尝试此操作

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

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

self.searchBar.tintColor = [UIColor blackColor];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM