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.
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.
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)
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.
}