I'm wanting to generate a UIImage that's a RGB gradient that also has a portion of black on the left side. I would like to do this programmatically, instead of having to make the image in Photoshop and using it as an asset in the app.
I've searched on here and have seen the generation of iOS color wheels before, but nothing like a rectangle below which I mocked in Photoshop:
This will be for letting users change text color as they touch inside of the UIImage.
I'm not really sure where to begin however, and would appreciate some pointers.
This is the code I used to make a color wheel before, but I need a rectangle (as shown above) now.
Result of that code:
I've searched on here and have seen the generation of iOS color wheels before, but nothing like a rectangle below which I mocked in Photoshop:

This will be for letting users change text color as they touch inside of the UIImage.
I'm not really sure where to begin however, and would appreciate some pointers.
This is the code I used to make a color wheel before, but I need a rectangle (as shown above) now.
Code:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(110, 110), YES, 0.0);
[[UIColor blackColor] setFill];
UIRectFill(CGRectMake(0, 0, 110, 110));
int sectors = 360;
float radius = MIN(100, 100)/2;
float angle = 2 * M_PI/sectors;
UIBezierPath *bezierPath;
for (int i = 0; i < sectors; i++)
{
CGPoint center = CGPointMake(55, 55);
bezierPath = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:i * angle endAngle:(i + 1) * angle clockwise:YES];
[bezierPath addLineToPoint:center];
[bezierPath closePath];
UIColor *color = [UIColor colorWithHue:((float)i)/sectors saturation:1. brightness:1. alpha:1];
[color setFill];
[color setStroke];
[bezierPath fill];
[bezierPath stroke];
}
self.colorWheelImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Result of that code:

Last edited: