核心图形渐变颜色的数组

时间:2012-02-03 14:36:20

标签: objective-c c core-graphics opengl-es-2.0

无法创建coreGraphic渐变颜色列表数组

我有两种类型渐变的if语句

CGFloat colors[8];

if (YES) {
    colors = {                               //expected expression error
        130/255.0f, 42/255.0f, 212/255.0f, 0.3,
        50/255.0f, 4/255.0f, 92/255.0f, 0.3
    };
} 
else {
    colors [] = {                             //expected expression error
        1.0, 1.0, 1.0, 1.0,
        207/255.0f, 207/255.0f, 207/255.0f, 1.0
    };
}

有人能告诉我我的错误在哪里吗?

1 个答案:

答案 0 :(得分:1)

你不能像那样分配数组。我建议你:

float col1[]={ 130/255.0f, 42/255.0f, 212/255.0f, 0.3,
        50/255.0f, 4/255.0f, 92/255.0f, 0.3};
float col2[]={1.0, 1.0, 1.0, 1.0,
        207/255.0f, 207/255.0f, 207/255.0f, 1.0};
float *colors;
if (YES) colors=col1;
else colors=col2;