I am creating buttons programmatically. I want to change button background color while touching up inside again it has to set back to its usual color after lifting up our finger…..
nine = [UIButton buttonWithType:UIButtonTypeCustom];
[nine setFrame:CGRectMake(15, 105, 65, 40)];
[nine setTitle:@"9" forState:UIControlStateNormal];
[nine setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[nine setBackgroundColor:[UIColor cyanColor]];
[nine addTarget:self action:@selector(clickDigit:) forControlEvents:UIControlEventTouchUpInside];
[nine addTarget:self action:@selector(changeButtonBackGroundColor:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nine];
// to change background color
-(void)changeButtonBackGroundColor:(id) sender
{
[nine setBackgroundColor:[UIColor redColor]];
}
Here changeBackgroundColor method was created to change color of that button . it changes color.
Don’t know if this relates to your question but:
this
should be
Edit:
Change this
to
and add the method: