[英]How can i change the fill color of a CALayer in Core Graphics?
我有一個形狀,一個CALayer,我想添加核心圖形效果。 現在,我想保持簡單並改變它的填充顏色。 我怎樣才能做到這一點?
如果您只想更改整個圖層的顏色,可以使用:
layer.backgroundColor = [[UIColor greenColor] CGColor];
如果你有一個更復雜的形狀,如填充路徑,你需要覆蓋圖層的drawInContext:
用這樣的:
- (void)drawInContext:(CGContextRef)context
{
//...
CGContextSetFillColorWithColor(context, [[UIColor greenColor] CGColor]);
CGContextFillPath(context);
//...
}
有關詳細信息,請參閱“ Quartz 2D編程指南” 。
shape.fillColor = [UIColor blackColor].CGColor;
我相信[[UIColor redColor] setFill]
正是你要找的。
我沒有Xcode打開atm,但如果你想填充路徑,這應該是正確的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.