0

I can access the the layer of the cell and update it background by this code:

if(cell.layer.sublayers.count < 3){
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.frame = cell.bounds;
        gradient.colors = [NSArray arrayWithObjects:(id)topGold.CGColor, (id)bottomSilver.CGColor, nil];
        [cell.layer insertSublayer:gradient atIndex:0];
}

But i dunno how to access the sub -UIView (title) contained inside the cell (cardCell), because I want to update the background of the view (title) background by layer too

enter image description here

Neo
  • 167
  • 1
  • 1
  • 12

1 Answers1

-1

You can simply iterate through the subviews of the cardCell.contentView to find the Title subview

NSArray *subviews = cell.contentView.subviews;

if ([subviews count] == 0) return; 

for (UIView *subview in subviews) {
   if (subview.tag == 5) {
    // do something
    NSLog(@"%@", subview);
   }


}
Arunabh Das
  • 13,212
  • 21
  • 86
  • 109
  • You can't access the subview from the cell's layer. You want `NSArray *subviews = cell.contentView.subviews;`. – rmaddy Apr 06 '16 at 01:51
  • I would also tag the UIView that you want to access in the story board, and then inside the for loop you can use an if statement, when you reach that UIView `if(subview.tag == 5){ //Do something }` – tennis779 Apr 06 '16 at 01:54
  • BTW - what good is it to iterate though all the subviews? How would you know which subview is the title? Just use tags and eliminate the looping. – rmaddy Apr 06 '16 at 01:57
  • there is error with this line of code NSArray *subviews = [cell.layer.sublayers subviews]; – Neo Apr 06 '16 at 02:18
  • Now replace all of that code with one line: `UIView *desiredSubview = [cell.contentView viewWithTag:5];` – rmaddy Apr 07 '16 at 22:43