P. Wright
P. Wright

Reputation: 133

Animating change to uitableviewcell's background color

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.

Upvotes: 1

Views: 2178

Answers (2)

Balu
Balu

Reputation: 8460

- (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];   
}

Upvotes: 3

Yatin Sarbalia
Yatin Sarbalia

Reputation: 209

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.

Upvotes: 0

Related Questions