Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change fillColor of selected CAShapeLayer

I'm trying to change the fillColor of a CAShapeLayer when the layer it's contained in is touched. I'm able to change the background color of the tapped layer like this:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point];
layer = layer.modelLayer;
layer.backgroundColor = [UIColor blueColor].CGColor;
}

This turns the background of "layer" blue as expected. My problem is how do I change the color of the CAShapelayer inside "layer"? Thanks!

like image 474
Frank Avatar asked Nov 23 '11 17:11

Frank


1 Answers

A CAShapeLayer has a property, fillColor, that you can pass in a CGColor to change:

CAShapeLayer* shapeLayer = (CAShapeLayer*)layer.modelLayer;
shapeLayer.fillColor = [UIColor blueColor].CGColor;

See also: CAShapeLayer Class Reference

like image 94
Wayne Hartman Avatar answered Oct 21 '22 19:10

Wayne Hartman