How can i change the fill color of a CALayer in Core Graphics?

calayer, core-graphics, ios, iphone, objective-c

Solution

If you just want to change the color of the whole layer you can use:

layer.backgroundColor = [[UIColor greenColor] CGColor];

if you have a more complex shape like a path to fill, you need to overwrite the layer's `drawInContext:` with sth like this:

- (void)drawInContext:(CGContextRef)context
{
    //...
    CGContextSetFillColorWithColor(context, [[UIColor greenColor] CGColor]);
    CGContextFillPath(context);
    //...
}

See Quartz 2D Programming Guide for more info.

Problem

I have a shape, a CALayer, which I want to add core graphics effects to. Right now, I want to keep it simple and change the fill colour of it. How can I do this?

Original source