0

I am trying to animate the color change of a cell using the following code. However, the color changes instantly no matter what I set the duration to. For labels, an answer on SO said you need to first set to clear color and I've done that but still no success.

Can anyone suggest how to do this?

cell.backgroundColor = [UIColor clearColor];
 [UIView animateWithDuration:10.0 delay:0.2 options:0 animations:^{
 cell.backgroundColor = [UIColor greenColor];
 } completion:^(BOOL finished)
 {
 NSLog(@"Color transformation Completed");
 }];
user6631314
  • 1,751
  • 1
  • 13
  • 44
  • 1
    You can't animate the background color of a UIView directly. You can, however, animate the layer. See https://stackoverflow.com/questions/3762561/how-to-animate-the-background-color-of-a-uilabel – brandonscript Aug 24 '17 at 19:30
  • The may be of help: https://stackoverflow.com/questions/14689190/how-can-i-animate-a-uitableviewcells-colors – palme Aug 24 '17 at 19:32
  • @brandonscript, I tried the layer method in that answer but same result: changes but without animation. – user6631314 Aug 24 '17 at 19:50
  • 1
    @user6631314 Simple trick would be adding a green view as background view and animate the alpha. – HMHero Aug 24 '17 at 19:54
  • animate alpha of background view or cell? I can't seem to get any animation to work for cell. – user6631314 Aug 25 '17 at 11:32

0 Answers0