1

Unfortunately there is no showsTouchWhenHighlighted for UIBarButtonItem and I can't edit my button from the toolbar...

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nili
  • 1,963
  • 3
  • 20
  • 39

1 Answers1

3

The property responsible for this is accessible in the UIButton class:

myButton.showsTouchWhenHighlighted = NO;

You can access this (programmatically) in a UIBarButtonItem by assigning a UIButton to the bar button item's customView property, and configuring the button. You can do this in Interface Builder too: drag a UIButton onto a UIToolbar, and it will automatically embed it in a UIBarButtonItem for you - then look for the "Shows Touch On Highlight" checkbox under the button's settings.

Incidentally, I don't know how you're customising your buttons so feel free to ignore this, but if your button looks and behaves like a standard toolbar item then users will expect the glow effect.

Answer from here

EDIT:

Try this then:

UIImage* buttonImage = [UIImage imageNamed: @"header.navigation.back.png"];     
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame =  CGRectMake(0.0, 0.0, buttonImage.size.width/2, 32);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(backToPriorView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];
Community
  • 1
  • 1
Anil
  • 2,430
  • 3
  • 37
  • 55
  • I specifically mentioned I cannot use the interface builder so it's irrelevant. So how can I use showsTouchWhenHighlighted after all? – Nili Nov 29 '12 at 10:12
  • Actually you need not add a UIImage. You can set the background of aButton to whatever you like. – Anil Nov 29 '12 at 10:37
  • I believe that code block is missing this call: `aButton.showsTouchWhenHighlighted = NO` (in Swift I'm using `aButton.adjustsImageWhenHighlighted = false`) – Nolan Amy Jun 04 '19 at 05:40