Anybody? I want to draw a circle in core graphics with four colors in it. i.e. four equally distributed colors, one in each quarter of the circle.
A:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect mainSquare = self.bounds;
CGContextSaveGState(context);
// Create circle path and clip
CGContextAddEllipseInRect(context, mainSquare);
CGContextClip(context);
// Define rects
CGRect topLeft = CGRectMake(mainSquare.origin.x, mainSquare.origin.y, mainSquare.size.width / 2, mainSquare.size.height / 2);
CGRect topRight = CGRectMake(mainSquare.size.width / 2, mainSquare.origin.y, mainSquare.size.width / 2, mainSquare.size.height / 2);
CGRect bottomLeft = CGRectMake(mainSquare.origin.x, mainSquare.size.height / 2, mainSquare.size.width / 2, mainSquare.size.height / 2);
CGRect bottomRight = CGRectMake(mainSquare.size.width / 2, mainSquare.size.height / 2, mainSquare.size.width / 2, mainSquare.size.height / 2);
// Define colors
CGColorRef topLeftColor = [[UIColor redColor] CGColor];
CGColorRef topRightColor = [[UIColor blueColor] CGColor];
CGColorRef bottomLeftColor = [[UIColor greenColor] CGColor];
CGColorRef bottomRightColor = [[UIColor yellowColor] CGColor];
// Fill rects with colors
CGContextSetFillColorWithColor(context, topLeftColor);
CGContextFillRect(context, topLeft);
CGContextSetFillColorWithColor(context, topRightColor);
CGContextFillRect(context, topRight);
CGContextSetFillColorWithColor(context, bottomLeftColor);
CGContextFillRect(context, bottomLeft);
CGContextSetFillColorWithColor(context, bottomRightColor);
CGContextFillRect(context, bottomRight);
CGContextRestoreGState(context);
}
macatomy
2010-06-24 19:18:05
thanx buddy.its working for me :)live long
Ameer Shakayb Arsalaan
2010-06-24 19:36:02
01 How to rotate a circle(Fortune wheel) clockwise and anticlockwise by touching circle in particular direction.i.e. if I touch circle and drag my fingur on Iphone in clockwise direction 'my circle will start rotation in clockwise direction and vice versa. If anybody have an idea about it please share it as soon as possible. Thanx in advance
Ameer Shakayb Arsalaan
2010-06-24 19:37:46
If it works, please considering accepting the answer :)
macatomy
2010-06-24 22:01:15