I have a view and I created some 8 buttons programmatically in that. The title color of buttons is white color. I want to change color of button title to green color when it is clicked. And if i click any other button, the previously clicked button title color should become white and current button title color should become green.
How to do that?
Initialize all your buttons like this
[mybutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[mybutton setTitleColor:[UIColor greenColor] forState:UIControlStateSelected];
[mybutton addTarget:self action:@selector(onclick:) forControlEvents:UIControlEventTouchUpInside];
then change the selected state of you button when clicked
-(void)onclick:(id)sender{
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
}
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