3

In the Maps app, when you press the tracking button in the lower left hand corner, it glows showing that it's pressed. This makes it behave like a radio button, and it will un-glow once you move the map. Is there a simple way to but a button into the pressed state?

brianegge
  • 29,240
  • 13
  • 74
  • 99

5 Answers5

11

I believe you are looking for the showsTouchWhenHighlighted property for the UIButton class. Give this a try.

myButton.showsTouchWhenHighlighted = YES;
Drewsmits
  • 1,384
  • 2
  • 14
  • 24
  • 2
    The question is about a UIBarButtonItem not a UIButton, so this is not relevant. – Emil Jun 17 '11 at 23:49
  • 3
    It's not clear from the question detail that that is the case. And anyways, you can create a UIBarButtonItem with a UIButton, so I believe my answer is relevant. UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:myButton]; – Drewsmits Jul 21 '11 at 20:03
  • I was searching for effect for UIButton, so thanks for your response! – mxg Dec 06 '12 at 10:55
10

Set its style to UIBarButtonItemStyleDone.

Tom Irving
  • 10,041
  • 6
  • 47
  • 63
3

You could make its customview a custom button like this:

`

UIImage *image = [UIImage imageNamed:@"someimage"];
UIImage *imageHL = [UIImage imageNamed:@"someimage_selected"];
button = [UIButton buttonWithType:UIButtonTypeCustom];

[button setImage:image forState:UIControlStateNormal];
[button setImage:imageHL forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(doStuff:) forControlEvents:UIControlEventTouchUpInside];    
myBarButtonItem.customView = button;

`

Kodejack
  • 441
  • 4
  • 7
1

Use UIBarButtonItemStylePlain.

UIBarButtonItemStylePlain
Glows when tapped.

an0
  • 17,191
  • 12
  • 86
  • 136
0

If you have a UIBarButtonItem with image/text or UIBarButtonSystemItem, then use UIBarButtonItemStylePlain

barButton.style = UIBarButtonItemStylePlain;

If you have a UIBarButtonItem with a custom view, then, for each UIButton should add the following code:

uiButton.showsTouchWhenHighlighted = YES;
mxg
  • 20,946
  • 12
  • 59
  • 80