今天遇到一個需求劳曹,要求修改UISearchBar的輸入框的顏色捣辆,于是就去找UISearchBar的聲明文件有關于顏色的方法有:
@property(null_resettable, nonatomic,strong) UIColor *tintColor;
@property(nullable, nonatomic,strong) UIColor *barTintColor
代碼:self.searchController.searchBar.barTintColor=[UIColor redColor];
Paste_Image.png
代碼:self.searchController.searchBar.tintColor =[UIColor greenColor];
屏幕快照 2016-06-26 下午3.52.19.png
但都不是我們想要的蔬螟,于是我打印了 self.searchController.searchBar.subviews 得到了 UITextField,那下面就簡單了:
UITextField *textfield = [[[self.searchController.searchBar.subviews firstObject] subviews] lastObject];
textfield.backgroundColor =[UIColor blueColor];
屏幕快照 2016-06-26 下午3.57.17.png