[英]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. 我有一个形状,一个CALayer,我想添加核心图形效果。 Right now, I want to keep it simple and change the fill colour of it.
现在,我想保持简单并改变它的填充颜色。 How can I do this?
我怎样才能做到这一点?
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: 如果你有一个更复杂的形状,如填充路径,你需要覆盖图层的
drawInContext:
用这样的:
- (void)drawInContext:(CGContextRef)context
{
//...
CGContextSetFillColorWithColor(context, [[UIColor greenColor] CGColor]);
CGContextFillPath(context);
//...
}
See Quartz 2D Programming Guide for more info. 有关详细信息,请参阅“ Quartz 2D编程指南” 。
shape.fillColor = [UIColor blackColor].CGColor;
[[UIColor redColor] setFill]
is what you're looking for, I believe. 我相信
[[UIColor redColor] setFill]
正是你要找的。
I don't have Xcode open atm, but that should be the right method if you're trying to fill a path. 我没有Xcode打开atm,但如果你想填充路径,这应该是正确的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.