I'm attempting to make a rotary color wheel. The issue I'm having is trying to divide the circle into sections. I'm able to construct the wheel and I'm able to have it rotate but can't seem to figure out how to divide that wheel into triangular sections so I can then give each triangle a different color. I don't want to use images for the triangles like many of the cocoa pods I've seen because I need the user to be able to choose how many sections (or triangles) the wheel is going to have. So the section number will change and the triangle's in the wheel need to adjust accordingly. I'm not sure if UIBezierPath will help me or not here. I'm new to Objective-C and a little lost. Thanks in advance!
Here is my code to construct the wheel:
-(id) initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber {
if ((self = [super initWithFrame: frame])) {
self.numberOfSections = sectionsNumber;
self.delegate = del;
[self drawWheel];
}
return self;
}
-(void) drawWheel {
container = [[UIView alloc] initWithFrame:self.frame];
container.backgroundColor = [UIColor whiteColor];
container.layer.cornerRadius = 100.0;
container.layer.borderColor = [UIColor blackColor].CGColor;
container.layer.borderWidth = 1.0;
CGFloat angleSize = 2*M_PI/numberOfSections;
for (int i = 0; i < numberOfSections; i++) {
*****CREATE A TRIANGLE HERE AND SET THAT TRIANGLE'S COLOR****
}
//7 Adds the container to the main control.
container.userInteractionEnabled = NO;
[self addSubview:container];
//8 Initialize sectors
sectors = [NSMutableArray arrayWithCapacity:numberOfSections];
if (numberOfSections % 2 == 0) {
[self buildSectorsEven];
} else {
[self buildSectorsOdd];
}
}
I want it to look something like the photos below. So if the user chooses 4 sections then the wheel will have 4 colors. if 8 sections then 8 colors, etc.: