I have Objective-C working code for six buttons but I don't seem to find how to change the state of a button using Swift. So how do I make the following code work in Swift?
[self.button2 setBackgroundImage:[UIImage imageNamed:@"button2_selected.png"] forState: UIControlStateSelected];
button1.selected = NO;
button2.selected = !button2.selected;
button3.selected = NO;
button4.selected = NO;
button5.selected = NO;
button6.selected = NO;
Check for this:
var var_button_ = UIButton()
var_button_.setBackgroundImage(UIImage(named: "button2_selected.png"), forState: UIControlState.Normal)
var_button_.selected = false
var_button_.selected = !var_button_.selected
//var_button_.selected = true
Thanks BY JNYJ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With