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?
Asked
Active
Viewed 4,317 times
5 Answers
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
-
2The question is about a UIBarButtonItem not a UIButton, so this is not relevant. – Emil Jun 17 '11 at 23:49
-
3It'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
-
UIBarButtonItemStyleDone is a "blue" button. I don't think this is a glow, right? – bentford Jun 29 '11 at 23:36
-
Well it's not technically a glow, but it is what the Maps app does (as mentioned in the question). – Tom Irving Jul 01 '11 at 10:46
-
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
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