Tint 2 UIButton on single Click

321 Views Asked by At

I have two button say button1 and button2 declared as

- (IBAction)button1:(id)sender;
  @property (strong, nonatomic) IBOutlet UIButton *button2;

What I want to do is, when button1 is click button 2's tint color should be changed, so its like both button1 and 2 are same, when I click on button1 the tint should also effect in button2 as if button2 is also clicked, so its appearance should be like clicking two buttons at once when I click on button1. Is this possible?

My UserInteraction for button2 is disabled as I dont need its click event. On my button1 click I need button2 to also tint giving it an appearance like button 1 and 2 are simultaneously clicked.

EDIT: Some of you guys are still not getting my point. Imagine that on the run time screen there are two buttons, Button1 and Button2, imagine Button1 is invisible. Now if I click on Button1 it should look on the screen that I just clicked Button2. Setting tint color will only set the button2 tintcolor but it will not give the button clicked effect.

3

There are 3 best solutions below

6
On

Yes all you have to do is connect to outlets to the buttons...Call them whatever you want. Pu this code in BOTH your IBActions.

   your1stButton.tintColor = [UIColor redColor];
   your2ndButton.tintColor = [UIColor redColor];

In the different actions change the color and be sure to change your1stButton and your2ndButton to your outlets name.

6
On

You need to set button1 and button2 to as an @property (outlet) in your header, as well as declaring the methods. In the - (IBAction)button1:(id)sender; method you can set the tint color like so: self.button2.tintColor = [UIColor redColor];

- (IBAction)button1:(id)sender
{
  self.button2.tintColor = [UIColor redColor];
}

- (IBAction)button2:(id)sender
{
  self.button1.tintColor = [UIColor redColor];
}
0
On
- (IBAction)button1:(id)sender;
{
   btn1.tintColor = [UIColor redColor];
   btn2.tintColor = [UIColor redColor];


}
- (IBAction)button2:(id)sender;
{

btn1.tintColor = [UIColor redColor];
   btn2.tintColor = [UIColor redColor];


}