So in my custom view, I'm trying to draw a white/gray gradient using Core Graphics. I have the following code:
UIColor *color1 = [UIColor whiteColor];
UIColor *color2 = [UIColor colorWithRed:209.0/255.0 green:212.0/255.0 blue:217.0/255.0 alpha:1.0];
CFMutableArrayRef colors = CFArrayCreateMutable(NULL, 0, NULL);
CFArrayAppendValue(colors, color1.CGColor);
CFArrayAppendValue(colors, color2.CGColor);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[2] = {0.0, 1.0};
CGGradientRef gradient = CGGradientCreateWithColors(colorspace, colors, locations);
CGContextDrawLinearGradient(UIGraphicsGetCurrentContext(), gradient, topCenter, bottomCenter, kCGGradientDrawsAfterEndLocation);
I think this code is fairly straightforward and should result in a nice white/gray gradient. But it doesn't; it draws a transparent/gray gradient.
I think it may have something to do with the view's background color, which is [UIColor clearColor]. But I cannot change that, as I need to have some portions of my view to be transparent.
Any ideas?
CGColorSpaceCreateDeviceRGB()toCGColorSpaceCreateDeviceGray()and that worked; the white color is correctly displayed now. But doesn't this mean that only gray colors are displayed? And how can I solve that? - Rits