开发者

How do I make a UIBarButtonItem 'glow'?

开发者 https://www.devze.com 2022-12-27 20:40 出处:网络
In the Maps app, when you press the tracking button in the lower left hand corner, it glows开发者_C百科 showing that it\'s pressed.This makes it behave like a radio button, and it will un-glow once yo

In the Maps app, when you press the tracking button in the lower left hand corner, it glows开发者_C百科 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?


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

myButton.showsTouchWhenHighlighted = YES;


Set its style to UIBarButtonItemStyleDone.


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;

`


Use UIBarButtonItemStylePlain.

UIBarButtonItemStylePlain
Glows when tapped.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消