vendredi 20 janvier 2017

Swift Radio Buttons - CheckBoxes - Swift 3

I work on Swift 3, and I'm trying to make checkboxes that behave like radio buttons. I explain myself : I have 8 buttons ; each has an "unchecked" image and a "checked" image. I want only 1 button to be selected (so, showing ITS "checked" image) at the time. The principle of radio buttons. So I tried using the @IBAction with each button, I've this :

@IBAction func tona1_changed(_ sender: Any) {
 if test_tona1.isSelected == true
        {
            test_tona1.setBackgroundImage(UIImage(named: "0b_unchecked"), for: UIControlState.normal)

            test_tona1.isSelected = false
        }
        else
        {
            test_tona1.setBackgroundImage(UIImage(named: "0b_checked"), for: UIControlState.normal)

            test_tona1.isSelected = true
        }}

It actually make the image switch between "uncheck" and "check" but I don't know at all how to make it interact with the other buttons. I tried using an array with the buttons's tags inside but I didn't have something working. I also tried to make a class but I don't know how it can work. Thanks!

Aucun commentaire:

Enregistrer un commentaire