iOS 设置UISearchBar 背景颜色

[searchBar setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]];

或者是:(其实原理是一样的,只是下边的这种情况是将系统的setBackgroundImage方法实现了而已)
UIView *firstSubView = searchBar.subviews.firstObject;
UIImageView *backgroundImageView = [firstSubView.subviews firstObject];
backgroundImageView.image = [UIImage imageWithColor:White_Color];

值得一提的是:

这种方法不能实现修改searBar的背景颜色,这就跟苹果api的实现方式有关了,值得深究。

你可能感兴趣的:(iOS 设置UISearchBar 背景颜色)