1

When a cell is selected from a table view, I'd like the cell's background color to change from white (or clear) to black and I'd like the change in color to be animated. Is this possible?

I know certain tricks are necessary to change the background color of a uitableview cell, and I understand those for the most part, but I'd like to take it one step further and animate the change of the cell's background color. I'm assuming this will be done in the didSelectRowAtIndexPath: method.

1

2 Answers 2

3
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.8];
    [self.tableView cellForRowAtIndexPath:indexPath].imageView.alpha = 1.0;
    [self.tableView cellForRowAtIndexPath:indexPath].backgroundColor=[UIColor redColor];

    [UIView commitAnimations];   
}
0

Well as of my knowledge, we cant animate the color change. What we can do , is to play a trick to change colors with a timer. The idea is, given two colors, startColor and endColor, one can easily find the in-between colors (lets say 20). And then using NSTimer we can set color property to each different color after regular intervals. This way, we can have a smooth transition/animation from startColor to endColor.

If anybody requires a code, then i can provide code also for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.