barTintColor
1. 获取到UISearchBar 中的searchField
UITextField *searchField = [searchBar valueForKey:@"searchField"];
可以进行设置
2. 更改searchBar的searchField外部的颜色.利用绘图获取.
_searchBar.backgroundImage = [self imageWithColor:[UIColor colorWithHexString:@"F4F5F7"] size:_searchBar.bounds.size];
//取消searchbar背景色
- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}