I have an IBOutletCollection of UIButton:
@IBOutlet var buttons: [UIButton]!
and a function for a tap:
@IBAction func butto
Try this code:
@IBOutlet var buttons: [UIButton]!
var lastTappedButton: UIButton?
@IBAction func button_Tap(_ sender: UIButton) {
for button in buttons {
if let lastTappedButton = lastTappedButton, lastTappedButton != sender {
button.backgroundColor = .white
}
if button.tag == sender.tag {
button.backgroundColor = .blue
lastTappedButton = button
}
}
}