Reputation: 1443
I'm trying to create a gradient texture in SpriteKit.
To do that, I have to use a CAGradientLayer
and render an image. My problem is with setting the colors.
From Apple's Documentation:
An array of
CGColorRef
objects defining the color of each gradient stop. Animatable.
So in code, I tried this:
gradient.colors = [NSArray arrayWithObjects:[UIColor redColor].CGColor, [UIColor whiteColor].CGColor, [UIColor blueColor].CGColor, nil];
This doesn't work, because CGColorRef
is not an object type and cannot be sent to type id
. My error is:
Incompatible pointer types sending
CGColorRef
(akastruct CGColor *
) to parameter of typeid
How can I create an array of CGColorRef
?
Upvotes: 2
Views: 2453
Reputation: 57114
Just use an array literal and cast to (id)
:
gradient.colors = @[(id)[UIColor redColor].CGColor, (id)[UIColor whiteColor].CGColor, (id)[UIColor blueColor].CGColor];
Upvotes: 6