0
我有三个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];