[英]how to dynamically recolor a CGGradientRef
我需要三個CGGradientRef,以便能夠動態重新着色。 第一次初始化CGGradientRef時,我得到了預期的結果,但是每次嘗試更改顏色時,都不會發生任何事情。 為什么?
漸變是CALayer子類中的一個實例變量:
@interface GradientLayer : CALayer
{
CGGradientRef gradient;
//other stuff
}
@end
碼:
if (gradient != NULL)
{
CGGradientRelease(gradient);
gradient = NULL;
}
RGBA color[360];
//set up array
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
gradient = CGGradientCreateWithColorComponents
(
rgb,
color,
NULL,
sizeof (color) / sizeof (color[0])
);
CGColorSpaceRelease(rgb);
[self setNeedsDisplay];
CGGradientRefs不能動態着色。 要動態為漸變着色,請使用CGShadingRef。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.