iOS 开发修改 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 redColor] size:self.searchBar.bounds.size];



你可能感兴趣的:(iOS,searchbar,自定义)