I had a quick question about creating a gradient in iOS7 that would fill just the view screen (story board). I was looking for a darker blue at the bottom with a gradient going up to a lighter blue. The problem is I'm not sure exactly how to do it.
I've played around with the below code, but I'm unable to quiet get it fixed correctly. Using the below code There is white at the top that fades into dark blue..... I'm trying to basically flip it.... with darker blue at the bottom of the screen getting lighter to light blue/almost white... I found code something like this elsewhere and pretty much have been attempting to alter it to get the results I would like without much luck... Could anyone help me break it down, or at least tell me how to fix it? It works... just not the results i'm trying to achieve.
Thank you
I've played around with the below code, but I'm unable to quiet get it fixed correctly. Using the below code There is white at the top that fades into dark blue..... I'm trying to basically flip it.... with darker blue at the bottom of the screen getting lighter to light blue/almost white... I found code something like this elsewhere and pretty much have been attempting to alter it to get the results I would like without much luck... Could anyone help me break it down, or at least tell me how to fix it? It works... just not the results i'm trying to achieve.
Thank you
Code:
CGContextRef ref = UIGraphicsGetCurrentContext();
UIColor *lightGradientColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.9 alpha:1.0];
UIColor *darkGradientColor = [UIColor colorWithRed:0.0 green:0.1 blue:0.4 alpha:1.0];
CGFloat locations[2] = {0.5, 1.0};
CFArrayRef colors = (__bridge CFArrayRef) [NSArray arrayWithObjects:(id)lightGradientColor.CGColor,(id)darkGradientColor.CGColor,nil];
CGColorSpaceRef colorSpc = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColors(colorSpc, colors, locations);
CGContextDrawLinearGradient(ref, gradient, CGPointMake(0.5, 0.0), CGPointMake(1.0, 70.0), kCGGradientDrawsAfterEndLocation); //Adjust second point according to your view height
CGColorSpaceRelease(colorSpc);
CGGradientRelease(gradient);
Last edited: