简体   繁体   English

更改所选CAShapeLayer的fillColor

[英]change fillColor of selected CAShapeLayer

I'm trying to change the fillColor of a CAShapeLayer when the layer it's contained in is touched. 我试图在触摸包含它的图层时更改CAShapeLayer的fillColor。 I'm able to change the background color of the tapped layer like this: 我可以像这样更改tapped图层的背景颜色:

-(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"? 我的问题是如何在“图层”中更改CAShapelayer的颜色? Thanks! 谢谢!

A CAShapeLayer has a property, fillColor , that you can pass in a CGColor to change: CAShapeLayer有一个属性fillColor ,你可以传入一个CGColor来改变:

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

See also: CAShapeLayer Class Reference 另请参见: CAShapeLayer类参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM