用UIColor创建UIImage

来源:互联网 发布:万人老虎机系统源码 编辑:程序博客网 时间:2024/06/08 06:03

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

    

    @autoreleasepool {

        

        CGRect rect = CGRectMake(00, 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
原创粉丝点击