Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keeping a UIButton pressed(state selected/highlighted),until another button is pressed?

I have 3 buttons at the bottom of my view controller, btn1 btn2 btn3, I'm using them instead of the tab bar as it is not possible to entirely customize a tab bar as per my requirements.

Now the issue is, when btn1 is pressed, I want it to change its image, to a grey rectangle, instead of the normal state image. I have set the images for both states in the outlet I declared for the button, btn1Outlet, using the setimage and uicontrolstate properties of the outlet.

The problem is, I can't keep the button selected until say either btn2 or btn3 is pressed. btn one changes to the selected state image only as long as it is pressed, the moment I leave it, it changes back to its normal state.

How can I keep btn1's image as selected image until any of the other 2 buttons are pressed?

like image 894
OccamsRazor Avatar asked Jun 24 '12 21:06

OccamsRazor


1 Answers

What you did is set an image for the "Highlighted" state, this is why when you push it you can see your image.

What you want to do is

1) set the image for the SELECTED state

2) create a property for your view controller (just controll drag the button to the header) using the assistant view (while on storyboard, second square on the top right)

3) on your method for the button's action type:

button.selected = !button.selected;

(obviously replace button to whatever you named your property to)

like image 127
Pochi Avatar answered Nov 15 '22 11:11

Pochi