- (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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2030 次 |
| 最近记录: |