how to dynamically recolor a CGGradientRef

Posted by saintmac on Stack Overflow See other posts from Stack Overflow or by saintmac
Published on 2010-05-21T23:08:11Z Indexed on 2010/05/21 23:10 UTC
Read the original article Hit count: 173

Filed under:
|
|

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 = CGColorSpaceCreateDeviceRGB();
    gradient = CGGradientCreateWithColorComponents
    (
    rgb, 
    color,
    NULL,
    sizeof (color) / sizeof (color[0])
    );
    CGColorSpaceRelease(rgb);
    [self setNeedsDisplay];

© Stack Overflow or respective owner

Related posts about core-graphics

Related posts about iphone