UIGraphicsBeginImageContext(CGSizeMake(512.0, 512.0));

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(ctx, [UIColor redColor].CGColor);
CGContextFillRect(ctx, CGRectMake(0.0, 0.0, 512.0, 512.0));
UIImage* myImage = UIGraphicsGetImageFromCurrentImageContext();
    
UIGraphicsEndImageContext();