quartz2D 填充圆形

来源:互联网 发布:手机发布淘宝宝贝 编辑:程序博客网 时间:2024/04/30 00:55
- (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);}
原创粉丝点击