iOS开发之修改UISearchBar的背景颜色

【iOS开发之修改UISearchBar的背景颜色】原文链接:http://www.cnblogs.com/Walking-Jin/p/5754519.html
定义方法

/** 取消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; }

调用
_searchBar.backgroundImage = [self imageWithColor:[UIColor clearColor] size:_searchBar.bounds.size];

    推荐阅读