I have a UIButton, and when tapped I want it to flash a background color, then return to its old color after some time.
Its old color isn't always the same, so I made a class variable.
Here is my current code, but I'm not sure how to achieve the time delay:
class ViewController: UIViewController {
///stuff
var oldColor: UIColor?
@IBAction func buttonPressed(_ sender: UIButton) {
oldColor = sender.backgroundColor
flashColor(sender, UIColor.green)
}
func flashColor(btn: UIButton, color: UIColor) {
btn.backgroundColor = color
wait(100ms) //I really have no idea how to do this part
btn.backgroundColor = oldColor
}
}