0

I have a UIButton, with this code to set the image based on the highlighted status:

UIImage *buttonImage = imageForButton(CGSizeMake(SquarePanelSize.width, SquarePanelSize.height), NO);
UIImage *buttonHighlightedImage = imageForButton(CGSizeMake(SquarePanelSize.width, SquarePanelSize.height), YES);
[self.addButton setImage:buttonImage forState:UIControlStateNormal];
[self.addButton setImage:buttonHighlightedImage forState:UIControlStateHighlighted];

The problem is that I want it to stay highlighted when the user has their finger on it, but it goes back to normal after a second.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Andrew
  • 15,935
  • 28
  • 121
  • 203

2 Answers2

1

had this issue myself a few days ago this was the fix i found throw this in your button was touched method/ ibaction

  [self performSelector:@selector(highlightButton:) withObject:sender afterDelay:0.0];

and then have a highlight button method for that

-(void)highlightButton:(UIButton *)sender
{
   sender.highlighted = YES;
}
rezand
  • 576
  • 3
  • 11
0

I think you should use setBackgroundImage method.

 [self.addButton setBackgroundImage:buttonHighlightedImage forState:UIControlStateHighlighted];

try this. It works fine for me. if this one didn't work then try this.

[self.addButton setImage:buttonHighlightedImage forState:(UIControlStateSelected | UIControlStateHighlighted)];
zedzhao
  • 517
  • 1
  • 3
  • 17