2010-05-21 30 views
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]; 

回答

0

CGGradientRefs不能动态着色。要动态地为渐变着色,请使用CGShadingRef。