【问题标题】:how to dynamically recolor a CGGradientRef如何动态重新着色 CGGradientRef
【发布时间】:2010-05-21 23:08:11
【问题描述】:

我需要能够动态重新着色的三个 CGGradientRef。当我第一次初始化 CGGradientRef 时,我得到了预期的结果,但每次我尝试更改颜色时都没有任何反应。为什么?

gradient 是 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];

【问题讨论】:

    标签: iphone objective-c core-graphics


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 2015-08-29
      • 1970-01-01
      • 2012-07-18
      • 2016-04-30
      • 1970-01-01
      • 2011-06-09
      相关资源
      最近更新 更多