GioB GioB - 1 year ago 120
Swift Question

Xcode Swift Ios App: Adding delay

I am working on a simple quiz game and i want to add some little delays to the game,now when i select the answer the game goes instantly to the next answer now i want to change the color of the button for 0.1 seconds and then loads the next question

I tried the sleep function but it adds only the delay without the color change and i can't choose time intervals smaller than a second because it accepts integers as value

here is the code

sender.backgroundColor = UIColor.greenColor()
sender.backgroundColor = UIColor.whiteColor()

what i have to put instead of sleep to obtain what i want?


Answer Source

You can use NSTimer for that, firstly you implement NSTimer and you add duration time 1.0 second or what ever want then, pass the time NSTimer call its function and you change questions to another

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download