由颜色初始化UIImage对象

来源:互联网 发布:新塘沙埔菜鸟网络招聘 编辑:程序博客网 时间:2024/05/18 01:33

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

    CGRect rect = CGRectMake(0.0f0.0f1.0f1.0f);//更改大小

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    CGContextSetFillColorWithColor(context, [color CGColor]);

    CGContextFillRect(context, rect);

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return image;

}


0 0
原创粉丝点击