objective c - iOS - Convert NSArray to float array -
i have array called self.gradientarray of colors. when print out looks this:
gradientsarray: ( "uidevicergbcolorspace 0.333333 0.811765 0.768627 1", "uidevicergbcolorspace 0.333333 0.811765 0.768627 1" ) i want convert array cgfloat array. example this:
cgfloat colors [] = { 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0 }; i tried , didn't work. i'm new objective-c , syntax please me.
cgfloat colors [] = self.gradientarray; i want use cgfloat array in making gradients this:
cggradientref gradient = cggradientcreatewithcolorcomponents(basespace, colors, null, 2);
the gradientsarray appear array of uicolor, in case like:
nsarray *gradientsarray = @[[uicolor redcolor], [uicolor bluecolor]]; cgfloat colors[gradientsarray.count * 4]; nsinteger index = 0; (uicolor *color in gradientsarray) { cgfloat red, green, blue, alpha; [color getred:&red green:&green blue:&blue alpha:&alpha]; colors[index++] = red; colors[index++] = green; colors[index++] = blue; colors[index++] = alpha; }
Comments
Post a Comment