Reputation: 309
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!
Upvotes: 9
Views: 10494
Reputation: 18477
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
Upvotes: 17