How to automatically draw a UIImage with frame and color?

I am trying to create a UIImage with frame and color, but don't know how to.

UIImage *aImage = [UIImage imageWithCIImage:[CIImage imageWithColor:[CIColor colorWithCGColor:[UIColor redColor].CGColor]]];

Is the specified string correct? How to create image size? Please, help!

0
source share
1 answer

enter a category UIImage.

eg UIImage(Color)

+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size
{
    UIGraphicsBeginImageContextWithOptions(size, YES, 0);

    [color set];
    UIBezierPath * path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, size.width, size.height)];
    [path fill];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
    UIGraphicsEndImageContext();

    return image;
}

How to use:

#import "UIImage + Color"

UIImage *image = [UIImage imageWithColor:[UIColor redColor] andSize:yourSize];
+7
source

All Articles