how to dynamically recolor a CGGradientRef
I have three CGGradientRef's that I need to be able to dynamically recolor. When I Initialise the CGGradientRef's the first time I get the expected result, but every time I attempt to change the colors nothing happens. Why?
gradient is an instance variable ins a subclass of CALayer:
@interface GradientLayer : CALayer
{
CGGradientRef gradient;
//other stuff
}
@end
Code:
if (gradient != NULL)
{
CGGradientRelease(gradient);
gradient = NULL;
}
RGBA color[360];
//set up array
CGColorSpaceRef rgb = CGColorSpaceCreateD开发者_如何学编程eviceRGB();
gradient = CGGradientCreateWithColorComponents
(
rgb,
color,
NULL,
sizeof (color) / sizeof (color[0])
);
CGColorSpaceRelease(rgb);
[self setNeedsDisplay];
CGGradientRefs cannot be dynamically colored. To dynamically color a gradient use a CGShadingRef.
精彩评论