获取指定颜色和大小的图片

来源:互联网 发布:mmd怎么保存姿势数据 编辑:程序博客网 时间:2024/05/19 18:13

/*

 @brief 获取指定颜色和大小的图片

 @param color 颜色

 @param size  尺寸

 */

+ (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 *img =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return img;

}

0 0