In UIView if you do the following:
CAGradientLayer *layer = [CAGradientLayer layer];
layer.colors = [NSArray arrayWithObjects:(id) [UIColor colorWithRed:0 green:0 blue:0.1 alpha:1].CGColor,[UIColor colorWithRed:0.3 green:0.3 blue:0.74 alpha:1].CGColor, nil];
layer.frame=CGRectMake(0, 0, self.frame.size.width,self.frame.size.height);
[self.layer insertSublayer:layer atIndex:0];
Will drawRect then perform custom drawing on top of this gradient? Does drawRect affect the actual background of a view, or is it a different layer entirely? If the background color of the view is clearColor does drawRect still display?
A sublayer obscures the content of its superlayer. If you override
drawRect:to draw content, that content will be obscured by the gradient layer.If you want to draw the gradient behind your (view) content, you should either draw the gradient in your
drawRect:instead of using a sublayer, or use a container view that contains both the gradient layer and yourdrawRect:-using content view, with your content view on top.Also, if you want the gradient layer to cover your view, it would be better to initialize
layer.framelike this: