Im just beginner in Swift Development. I don't know how to remove the .isSelected when the user choose the other button
How can i remove the .isSelected when the user pressed other button
202 Views Asked by coderchris121496 At
2
There are 2 best solutions below
0
On
I would create an array of buttons
@IBOutlet var buttonsArray: [UIButton]!
and then assign the same function for all buttons
for button in buttonsArray {
button.addTarget(self, action: #selector(buttonClicked(_:)), for: .touchUpInside)
}
When the user clicks the button, you can do whatever you want to with clicked button and with other buttons
@objc func buttonClicked(_ sender: UIButton) {
for button in buttonsArray {
if (button != sender) {
//Do what you need with not clicked button
}
}
//Do what you need with clicked button
}
maybe this is useful for you :
if you have several buttons and every one have different action you can follow these level :
1- in attribue inspector for your button choose a tag for example button 1 tag is 1
2- in the code action one button and connect it for each Botton
3- you can access to every button with this one of a code :