Domness
Domness

Reputation: 7605

Flashing Colours

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.

Upvotes: 0

Views: 634

Answers (1)

Andrew Grant
Andrew Grant

Reputation: 58786

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

Upvotes: 3

Related Questions