iOS 开发修改 searchbar 的背景颜色

来源:互联网 发布:php项目开发流程 编辑:程序博客网 时间:2024/04/30 12:49


/**先取消背景颜色*/

- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {

    CGRect rect =CGRectMake(0,0, size.width, size.height);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context =UIGraphicsGetCurrentContext();

    

    CGContextSetFillColorWithColor(context, [colorCGColor]);

    CGContextFillRect(context, rect);

    

    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return image;

}


/**调用*/

_searchBar.backgroundImage = [selfimageWithColor:[UIColorredColor] size:self.searchBar.bounds.size];



0 0