[英]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.