views:

300

answers:

1

I am trying to get the iPhone background Color to change color every X number of seconds.

How can I do this?

I've been trying a UIAnimation but can only get it to change to the very last color in a list.

Thanks alot!

+1  A: 

You could use a custom animation to step through an array of colors, or just use a timer. The timer would call a function that sets the chosen background color and then calls setNeedsDisplay on the view. E.e.

-(void) timerEntry
{
  UIColor* color = [colorArray objectAtIndex: colorIndex++];
  self.backgroundColor = color;
  [self setNeedsDisplay];
  if (colorIndex == [colorArray count])
    colorIndex = 0;
}

Then to setup the timer:

[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(timerEntry) userInfo: nil repeats: NO];
Andrew Grant
How do I implement the array and the colorIndex thing?
Domness
The array is an array of colors you wish to use, with colorIndex representing the current selection. That was just sample code, you can have the timerEntry function choose colors however you like.
Andrew Grant