Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 859
Andrew Avatar asked Apr 11 '13 21:04

Andrew


2 Answers

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.

like image 150
Tobi Avatar answered Oct 20 '22 00:10

Tobi


shape.fillColor = [UIColor blackColor].CGColor;
like image 23
Jayson Lane Avatar answered Oct 20 '22 01:10

Jayson Lane