I'm trying to create a Quiz app that consists of two buttons, false and true button. My question is, when I press one of the two buttons, I want it to change its background colour ONLY SHORTLY when its pressed then I want it to go back to the color it originally was, but I can not figure out how to change the background color shortly. This is the code I have for this part so far:
@IBAction func answerButtonPressed(_ sender: UIButton) {
let userAnswer = sender.currentTitle
let actualAnswer = quiz[questionNumber].answer
if userAnswer == actualAnswer {
sender.backgroundColor = UIColor.green
} else {
sender.backgroundColor = UIColor.red
}
if questionNumber + 1 < quiz.count {
questionNumber += 1
}
else {
questionNumber = 0
}
updateUI()
}
func updateUI() {
questionLabel.text = quiz[questionNumber].text
trueButton.backgroundColor = UIColor.clear
falseButton.backgroundColor = UIColor.clear
}