//设置searchBar Placeholder的字体颜色
// [[UILabel appearanceWhenContainedIn:[_searchBar class], nil] setTextColor:[UIColor grayTextColor]];
// Get the instance of the UITextField of the search bar
UITextField *searchField = [_searchBar valueForKey:@"_searchField"];
// Change search bar text color
searchField.textColor = [UIColor whiteColor];
// Change the search bar placeholder text color
[searchField setValue:[UIColor grayTextColor] forKeyPath:@"_placeholderLabel.textColor"];
if(__gSystemVersion >= 7){
_searchBar.searchBarStyle = UISearchBarStyleDefault;
}
searchBar.backgroundColor = bgColor;
UIView *topView = searchBar;
if (__gSystemVersion >= 7.0) {
topView = [[searchBar subviews] objectAtIndex:0];
searchBar.barTintColor = [UIColor clearColor];
}
//隐藏searchBar的默认背景
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subView removeFromSuperview];
break;
}
}