I have an array of buttons which will act like a selector menu. I want that when I press one of them, it changes its backgroundColor and all the other buttons go back to their initial color.
This is what I have at the moment
@IBAction func optionSelected(_ sender: UIButton) {
for button in selectButtons {
if button.tag == sender.tag {
if !button.isSelected {
button.backgroundColor = palette.importantColorObject()
button.isSelected = true
} else {
button.backgroundColor = palette.clearGrayColorObject()
button.isSelected = false
}
}
}
But I don't know how to make that only the last selected button have this importantColorObject
and I'm also having the problem that when I select the button, not only its background color changes, but it looks also like if text inside was being selected (in blue). How can I solve this?
Thanks in advance