views:

46

answers:

1

I have a view with has another view (called swipeView) inside it. I'm trying to gradient color it using the CAGradientLayer - the code is below

CAGradientLayer *layer = [CAGradientLayer layer];

layer.colors = [NSArray arrayWithObjects:(id)[UIColor darkGrayColor].CGColor, 
                  [UIColor lightGrayColor].CGColor, nil];

layer.frame = swipeView.bounds;

[swipeView.layer insertSublayer:layer atIndex:0];

I'm calling this in the ViewDidLoad method of the main view controller. I see no effect - the view I'm trying to color remains just the same. What am I doing wrong? Are there any other settings/ordering etc. I should know about?

A: 

That should work. Are you sure you hooked up your swipeView outlet correctly? Debug your -viewDidLoad and verify that swipeView is not nil. Also double check that the bounds (layer.frame) is something sensible.

It shouldn't be necessary, but you can try throwing in a [layer setNeedsDisplay] just to force the layer to render again, but I don't think that is your issue here.

Jason Foreman