0

I know this might have been asked before but, I've been trying to find an answer to this for ages. I am new to Xcode and would like to know, how do you change a buttons background colour when it is tapped?

Thanks

Volker
  • 4,640
  • 1
  • 23
  • 31

2 Answers2

7

Below code will change your button's background color to a blackColor.. You can change to whatever color you desire

- (IBAction)buttonClicked:(id)sender {

    yourButton.backgroundColor = [UIColor blackColor];


}
Ash
  • 5,525
  • 1
  • 40
  • 34
4GetFullOf
  • 1,738
  • 4
  • 22
  • 47
4

You can call setBackgroundColor: in method which fired when button pressed:

- (IBAction)buttonPressed:(id)sender
{
    UIButton *btn = (UIButton*)sender;
    [btn setBackgroundColor:[UIColor redColor]];
}
Greg
  • 25,317
  • 6
  • 53
  • 62