2

When the user presses the bar button, it changes its color to grey. But the color of the bar button shouldn't change when the state is pressed. I have the same problem like this question which never got solved and every answer is not working. There is no setUserInteractionEnabled property. But disabling the whole bar button brings an alpha effect on the bar button wich I dont want to.

Any advice?

Megaetron
  • 1,154
  • 2
  • 15
  • 29

2 Answers2

4

You're right, there's no elegant solution. The best way to do this is to use a UIButton in the toolbar. Look at the EDIT part in this answer: How do I remove UIBarButtonItem glow programtically?

Community
  • 1
  • 1
scott
  • 1,194
  • 7
  • 18
1

I had similar problem , i solved it by setting same image for both UIControlStateNormal and UIControlStateDisabled.Then disable the bar button.

UIImage *buttonImage = [UIImage imageNamed:@"ic_launcher.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
[aButton setImage:buttonImage forState:UIControlStateDisabled];
aButton.frame = CGRectMake(0.0,0.0,50,50);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
backButton.enabled = NO;
self.navigationItem.leftBarButtonItem = backButton;
RavikanthM
  • 468
  • 3
  • 17
  • Thanks for that. I think that only setting the disabled state is enough, since you hardcode the bar button in a disabled state – micaste Jul 13 '21 at 01:27