I have multiple buttons, representing data input (scores). When 1 button is selected, change it's background to 1 colour. All other buttons should be set to a different colour, showing which is currently selected (toggled).
I have used the info from this thread to implement an @IBAction function to change the button. I used the Swift v4 reply / solution as the basis, essentially a single function as:
@IBAction func buttonPressToggle(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
if sender.isSelected {
sender.backgroundColor = UIColor.orange
} else {
sender.backgroundColor = UIColor.green
}
}
All buttons use the same function, so I can target the button through the sender
local variable. I can also use the tag
property, but I haven't done anything with this currently.
What is missing with this is to "reset" any other button's state / background colour, as it is no longer selected.