Can anybody help me in changing the text color when user selected. Like I have three buttons on one viewcontroller and when users taps on 1 button it changes to white and the rest of two become grey.
You have to do same thing for all buttons in your interfaceBuilder
Then create outlet for all buttons
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!
@IBOutlet weak var button3: UIButton!
Create action for all buttons
@IBAction func buttonOneAction(sender: AnyObject) {
button1.selected = true;
button2.selected = false;
button3.selected = false;
}
@IBAction func buttonTwoAction(sender: AnyObject) {
button1.selected = false;
button2.selected = true;
button3.selected = false;
}
@IBAction func buttonThreeAction(sender: AnyObject) {
button1.selected = false;
button2.selected = false;
button3.selected = true;
}
output: middle button is selected
You'll need to use setTitleColor(_:forState:)
.
// Setting the color for a button's disabled state to red
button.setTitleColor(UIColor.redColor(), forState: .Disabled)
UIButton Class Reference
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