1
backround.backgroundColor = UIColor.redColor()
//Delay code ?
backround.backgroundColor = UIColor.blueColor()

Is there anyway to do this? I do not know the exact code line to create this type of delay.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0
func performDelayBlock(block:() -> Void, afterDelay delay:NSTimeInterval)
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), block)
}

usage:

backround.backgroundColor = UIColor.redColor()
performDelayBlock({ 
    self.backround.backgroundColor = UIColor.blueColor()
    }, afterDelay: 1)
Ayman Ibrahim
  • 1,359
  • 15
  • 24
0

You can do it using NSTimer.

//Register for NSTimer wherever you are setting your first color and then set the interval time. 
//Since you want to repeat you can just do repeat to be true 
NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "changeBackground", userInfo: nil, repeats: true)




func changeBackground() {
    backround.backgroundColor = UIColor.redColor() //whichever you like
   //Have conditional code to change it back and forth to red and other color you want to.
}
user2884707bond
  • 559
  • 4
  • 24