ios - Assigning of floats into global array -


i'm trying customize grouped uitableviewcell's backgroundview gradient, based on code find on blog. it's subclass of uiview use on cell.backgroundview.

the colors of background's gradient defined on original code :

#define table_cell_background    { 1, 1, 1, 1, 0.866, 0.866, 0.866, 1}          // #ffffff , #dddddd 

and then, used on drawrect of subclassed backgroundview:

cgfloat components[8] = table_cell_background; mygradient = cggradientcreatewithcolorcomponents(mycolorspace, components , locations, 2); 

i'm trying implement function set start , end color gradient, takes 2 uicolors , fill in global float array float startandendcolors[8] (in .h / @interface) later use:

-(void)setcolorsfrom:(uicolor*)start to:(uicolor*)end{      float red = 0.0, green = 0.0, blue = 0.0, alpha =0.0, red1 = 0.0, green1 = 0.0, blue1 = 0.0, alpha1 =0.0;      [start getred:&red green:&green blue:&blue alpha:&alpha];     [end getred:&red1 green:&green1 blue:&blue1 alpha:&alpha1];      //this line works fine, array filled, test     float colorstest[8] = {red, green, blue, alpha, red1, green1, blue1, alpha1};      //but one, have error.     //"expected expression"     //                 \     //                  v     startandendcolors = {red, green, blue, alpha, red1, green1, blue1, alpha1}; } 

but throw me error "expected expression" @ assignation.

i tried cgfloat, desperately adding random const, ran out of ideas.

i don't it, why can't fill float array way? doing wrong?

comment added answer:

the way of creating array way dynamically in code. if adding ivar (class variable) need go through 1 one because memory has been allocated @ initialization. use startandendcolors[0] = ..., etc.

as follow question: no, there no way assign values in way memory has been initialized in allocation phase. if used std::vector or other objects possible.

a way around in header

cgfloat *startandendcolors; 

and in implementation

float colorstest[8] = {red, green, blue, alpha, red1, green1, blue1, alpha1}; startandendcolors = colorstest; 

that way can initialize way want to, have no guarantee of number of objects in startandendcolors object. later assign of wrong size , cause crashes if try access outside of it's bounds.


Comments