iOS 根据颜色生成图片

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/C_calary/article/details/82021933
// 根据颜色生成UIImage
- (UIImage*)imageWithColor:(UIColor*)color{

    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    // 开始画图的上下文
    UIGraphicsBeginImageContext(rect.size);

    // 设置背景颜色
    [color set];
    // 设置填充区域
    UIRectFill(CGRectMake(0, 0, rect.size.width, rect.size.height));

    // 返回UIImage
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    // 结束上下文
    UIGraphicsEndImageContext();
    return image;
}

猜你喜欢

转载自blog.csdn.net/C_calary/article/details/82021933
今日推荐