I am currently using the following method to set the background color of my view
//Set the background color
CAGradientLayer *bgLayer = [BackgroundLayer blueGradient]; <---Calls method below
bgLayer.frame = self.view.bounds;
//self.view.layer.backgroundColor = [UIColor redColor].CGColor;
[self.view.layer insertSublayer:bgLayer atIndex:0];
This is how it obtains the gradient color - this is the method is called above
@implementation BackgroundLayer
//Blue gradient background
+ (CAGradientLayer*) blueGradient {
UIColor *colorOne = [UIColor colorWithRed:(120/255.0) green:(135/255.0) blue:(150/255.0) alpha:1.0];
UIColor *colorTwo = [UIColor colorWithRed:(57/255.0) green:(79/255.0) blue:(96/255.0) alpha:1.0];
NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];
NSNumber *stopOne = [NSNumber numberWithFloat:0.0];
NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];
NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil];
CAGradientLayer *headerLayer = [CAGradientLayer layer];
headerLayer.colors = colors;
headerLayer.locations = locations;
return headerLayer;
}
@end
Now in the portrait mode the background appears fine. However in Landscape mode it only covers half the screen and the other half is white. Why is that ? And how can I fix it. I tried the following for changing the color
self.view.layer.backgroundColor = [UIColor redColor].CGColor;
The above works fine both in landscape an portrait mode however its not a gradient. Any ideas on how I can make the gradient work ?