Helium3 Helium3 - 11 months ago 77
iOS Question

CGGradient with 3 colors

How does one draw a CGGradient with 3 colors?

I have an array like so:

CFArrayRef colors = (__bridge CFArrayRef) [NSArray arrayWithObjects:(id)lightGradientColor.CGColor,
(id)darkGradientColor.CGColor, (id)lightGradientColor.CGColor,

but I dont see the dark color in the middle with light on top and bottom sections, but rather just light on top, with dark until the bottom.

Answer Source

Have you tried specifying/verifying the locations of your colors? The range is [0...1]:

const CGFloat locations[3] = {0.0, 0.5, 1.0};
CGGradientRef grad = CGGradientCreateWithColors(colorspace, colors, locations);

note: The locations above should be the same as passing 0 for the locations parameter.