Reputation: 6335
-Hello, how can I add a CAGradientLayer to a tableview cell. The table view is in grouped mode that means it can have rounded corners as well. I tried:
CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
gradientLayer.frame = cell.frame;
gradientLayer.colors = [NSArray arrayWithObjects:
[UIColor redColor].CGColor,
[UIColor blueColor].CGColor, nil];
gradientLayer.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat: 0],
[NSNumber numberWithFloat: 1], nil];
gradientLayer.masksToBounds = true;
[cell.backgroundView.layer addSublayer: gradientLayer];
//[cell.contentView.layer addSublayer : gradientLayer];
[gradientLayer release];
If I set masksToBounds = true
does that in any way affect the layer's corner radius?
If I add to the contentview it hides everything from the cell. If I add to the backgroundview it almost never shows, when it shows it is without rounded corners and only in the bottom part of the first cell, I have no idea why.
I add the gradient layer in my
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method. Is this the right way to do this? Will I have rounded corners without manually using some paths or something? Any help is appreciated.
Upvotes: 1
Views: 4202
Reputation: 3376
Have a look at these pages
Upvotes: 1