改变searchBar的样式
// 找到searchbar的searchField属性
UITextField *searchField = [self.searchBar valueForKey:@"searchField"];
if (searchField) {
// 背景色
[searchField setBackgroundColor:[UIColor colorWithRed:0.074 green:0.649 blue:0.524 alpha:1.000]];
// 设置字体颜色 & 占位符 (必须)
searchField.textColor = [UIColor whiteColor];
searchField.placeholder = @"placeholder";
// 根据@"_placeholderLabel.textColor" 找到placeholder的字体颜色
[searchField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
// 圆角
searchField.layer.cornerRadius = 10.0f;
searchField.layer.masksToBounds = YES;
}
如果要改变searchBar的图标样式可以使用
// searchBar 图标设置
[self.searchBar setImage:[UIImage imageNamed:@"magnifier"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
网络不好不上效果图了