Display only simple colors

I am trying to render a gradient using CAGradientLayers.
I just set two colors and I expect to see a gradient between them, unfortunately only the first plain color is displayed without a gradient.

Here is my code:

- (void)viewDidLoad {
[super viewDidLoad];

CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0.0, 0.0, 480.0, 320.0);
gradientLayer.colors = [NSArray arrayWithObjects:
                        (id)[UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0].CGColor,
                        (id)[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.0].CGColor,
                        nil];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(480, 320);

[self.view.layer addSublayer:gradientLayer];
}

      

Any help would be greatly appreciated!

+2


source to share


1 answer


The endPoint property must be between 0.0 and 1.0.



+8


source







All Articles