修改搜尋框的背景顏色,最有效的方法
阿新 • • 發佈:2019-02-09
//去掉搜尋框背景
self.searrchBar.backgroundImage = [selfimageWithColor:[UIColorclearColor] size:self.searrchBar.bounds.size];
//取消searchbar背景色x
- (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;
}