CGGradient Not Displaying Correctly on iPad 1 and 2

Posted by daveMac on Stack Overflow See other posts from Stack Overflow or by daveMac
Published on 2012-06-11T22:18:09Z Indexed on 2012/06/11 22:40 UTC
Read the original article Hit count: 249

Filed under:
|
|
|

I have been experimenting with creating my own gradients for the UI in my iOS app. I first used a CAGradientLayer but I was disappointed with the "stepped" look so I have been trying out CGGradient. enter code here

I am having an issue with the Gradient displaying correctly. I have three iPads—one for each generation. The gradient looks right on the iPad 3 but not on the iPad 1 or 2. This is really strange. I was going to take a screenshot and post the two differences but even more strange, the screenshot look the same (and yes, the brightness is the same on both).

The colors seem really washed out on the older iPads. I know the iPad 3 is a retina display, but I think it must be something more than that. Here is the code I am using:

- (void)drawRect:(CGRect)rect
{

    CGContextRef currentContext = UIGraphicsGetCurrentContext();

    CGGradientRef skyGradient;
    CGColorSpaceRef rgbColorspace;
    size_t num_locations = 3;
    CGFloat locations[3] = { 0.0, .5, 1.0 };
    CGFloat components[12] = { .106, .73,  .93333, 1.,
                              0.0,  0.0 , 1.0,     1., 
                               .106, .73,  .93333, 1. };

    rgbColorspace = CGColorSpaceCreateDeviceRGB();
    skyGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);

    CGRect currentBounds = self.bounds;
    CGPoint topLeft = CGPointMake(0.0f, 0.0f);
    CGPoint bottomRight = CGPointMake(CGRectGetMaxX(currentBounds), CGRectGetMaxY(currentBounds));
    CGContextDrawLinearGradient(currentContext, skyGradient, topLeft, bottomRight, 0);

    CGGradientRelease(skyGradient);
    CGColorSpaceRelease(rgbColorspace); 

}

Not a great picture, but you can still see a drastic difference.

© Stack Overflow or respective owner

Related posts about ios

Related posts about iPad