0

I'm pretty new to iOS developpement, and I'm trying to set my view background to a gradient. I created a CAGradientLayer and try to set it. It goes throught building, but my app crashes as soon as it open, throwing a "EXC_BAD_ACCESS". Here is my code:

- (void)viewWillAppear:(BOOL)animated
 {

 [super viewWillAppear:animated];

CAGradientLayer     *bgLayer = [CAGradientLayer layer];
UIColor             *grey = [UIColor colorWithRed:(255/255.0) green:(255/255.0) blue:(255/255.0) alpha:1.0];
UIColor             *black = [UIColor colorWithRed:(180/255.0) green:(180/255.0) blue:(180/255.0) alpha:1.0];
NSNumber            *top = [NSNumber numberWithFloat:0.0];
NSNumber            *bot = [NSNumber numberWithFloat:1.0];

bgLayer.colors = [NSArray arrayWithObjects:grey, black, nil];
bgLayer.locations = [NSArray arrayWithObjects:top, bot, nil];
bgLayer.frame = self.view.bounds;
[self.view.layer addSublayer:bgLayer];
}

I think I understood that it comes from a bad memory management, but don't what I did wrong. Thanks for your answers in advance.

tomahh
  • 13,441
  • 3
  • 49
  • 70

1 Answers1

1

Note what the docs say about the colors:

An array of CGColorRef objects defining the color of each gradient stop.

borrrden
  • 33,256
  • 8
  • 74
  • 109
  • Woaw, I didnt even think about checking the documentation. I'm sorry wasting your time. Thanks a lot anyways. – tomahh Jul 13 '12 at 02:18
  • It will be a good habit to always check the docs first :). There is a lot of info there. – borrrden Jul 13 '12 at 02:20