//自定义 searchBar的搜索按钮
for(UIView *view in [[[self.searchBar subviews] objectAtIndex:0] subviews]) {
if([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {
UIButton * cancel =(UIButton *)view;
[cancel setTitle:@"搜索" forState:UIControlStateNormal];
[cancel setTitleColor:RGBColor(51, 51, 51) forState:UIControlStateNormal];
[cancel addTarget:self action:@selector(seatchAction) forControlEvents:UIControlEventTouchUpInside];
}
}
//自定义 searchBar的搜索框的背景亚颜色
for (UIView* subview in [[self.searchBar.subviews lastObject] subviews]) {
if ([subview isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField*)subview;
textField.textColor = [UIColor blackColor]; //修改输入字体的颜色
[textField setBackgroundColor:RGBColor(238, 238, 238)]; //修改输入框的颜色
[textField setValue:RGBColor(174, 174, 174) forKeyPath:@"_placeholderLabel.textColor"]; //修改placeholder的颜色
} else if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
}
}