Reputation: 2250
I have the following shape which I need to fill with a color or a background image:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGMutablePathRef pPath_0 = CGPathCreateMutable();
CGPathMoveToPoint(pPath_0, NULL, 72.61 / 2 + xCoordinates,20.21 / 2 + yCoordinates);
CGPathAddLineToPoint(pPath_0, NULL, 69.19 / 2 + xCoordinates,16.37 / 2 + yCoordinates);
CGPathAddLineToPoint(pPath_0, NULL, 26.02 / 2 + xCoordinates,16.37 / 2 + yCoordinates);
CGPathAddLineToPoint(pPath_0, NULL, 22.69 / 2 + xCoordinates,20.21 / 2 + yCoordinates);
CGPathAddCurveToPoint(pPath_0, NULL, 22.69 / 2 + xCoordinates,20.21 / 2 + yCoordinates,17.69 / 2 + xCoordinates,24.84 / 2 + yCoordinates,17.69 / 2 + xCoordinates,34.71 / 2 + yCoordinates);
CGPathAddLineToPoint(pPath_0, NULL, 17.69 / 2 + xCoordinates,194.87 / 2 + yCoordinates);
CGPathAddCurveToPoint(pPath_0, NULL, 17.69 / 2 + xCoordinates,194.87 / 2 + yCoordinates,20.87 / 2 + xCoordinates,206.37 / 2 + yCoordinates,47.69 / 2 + xCoordinates,206.37 / 2 + yCoordinates);
CGPathAddLineToPoint(pPath_0, NULL, 48.69 / 2 + xCoordinates,206.37 / 2 + yCoordinates);
CGPathAddCurveToPoint(pPath_0, NULL, 75.69 / 2 + xCoordinates,206.37 / 2 + yCoordinates,77.69 / 2 + xCoordinates,194.87 / 2 + yCoordinates,77.69 / 2 + xCoordinates,194.87 / 2 + yCoordinates);
CGPathAddLineToPoint(pPath_0, NULL, 77.69 / 2 + xCoordinates,34.71 / 2 + yCoordinates);
CGPathAddCurveToPoint(pPath_0, NULL, 77.69 / 2 + xCoordinates,24.84 / 2 + yCoordinates,72.61 / 2 + xCoordinates,20.21 / 2 + yCoordinates,72.61 / 2 + xCoordinates,20.21 / 2 + yCoordinates);
CGPathCloseSubpath(pPath_0);
CGContextSetRGBStrokeColor(context,0.0000,0.0000,0.0000,1.0000);
CGContextSetLineWidth(context, 1);
CGContextSetMiterLimit(context, 10.0000);
CGContextAddPath(context, pPath_0);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(pPath_0);
CGContextRestoreGState(context);
I'm trying to use the following code to fill the shape with a red color but it doesn't work:
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextDrawPath(context, kCGPathFill);
CGContextFillPath(context);
What am I missing?
Upvotes: 0
Views: 4260
Reputation: 2250
Fixed it:
CGContextAddPath(context, pPath_0);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextDrawPath(context, kCGPathFill);
CGContextFillPath(context);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(pPath_0);
CGContextRestoreGState(context);
Upvotes: 1