cdub
cdub

Reputation: 25751

Creating gradients with Core Graphics in iOS

I have the following code to create a gradient (or start of one):

CAGradientLayer *gradient = [CAGradientLayer layer];


UIColor *lightGreen = [UIColor colorWithRed:66.0f/255.0f green:79.0f/255.0f blue:91.0f/255.0f alpha:1.0f];
UIColor *darkGreen = [UIColor colorWithRed:66.0f/255.0f green:79.0f/255.0f blue:91.0f/255.0f alpha:1.0f];

Why does this line give me "Expected identifier"?

gradient.colors = [NSArray arrayWithObjects:(id)[lightGreen.CGColor]];

Upvotes: 0

Views: 186

Answers (1)

rckoenes
rckoenes

Reputation: 69499

You have to many [ in your code and you are not closing with , nil:

gradient.colors = [NSArray arrayWithObjects:(id)[lightGreen.CGColor]];

Should be:

gradient.colors = [NSArray arrayWithObjects:(id)lightGreen.CGColor, nil];

Or even:

gradient.colors = @[(id)lightGreen.CGColor];

Upvotes: 1

Related Questions