views:

61

answers:

3

Hi Buddies,

I have created five buttons in the view controller. If i clicked the button it goes to the corresponding view. Now i want to display the button in highlighted state when it is clicked. It should go back to the normal state only when i click the other button. I have set the another image for highigthting buttons when i clicked it, but it shows that highlighted state only one sec. Now i want to display the buttons highlighted till another button is clicked. Same like a Tabbar operations.(I have used buttons instead of tabbar for the requirements).

Now i have used the following code,

void didLoad
{

    [btn1 setImage:[UIImage imageNamed:@"ContentColor.png"]  forState:UIControlStateHighlighted];
    [btn2 setImage:[UIImage imageNamed:@"bColor.png"] forState:UIControlStateHighlighted];
    [btn3 setImage:[UIImage imageNamed:@"ShColor.png"] forState:UIControlStateHighlighted];
    [btn4 setImage:[UIImage imageNamed:@"PicturesColor.png"] forState:UIControlStateHighlighted];
    [btn5 setImage:[UIImage imageNamed:@"infoColor.png"] forState:UIControlStateHighlighted];
}

Please help me out.

Thanks.

+1  A: 

Simple solution would be...

on every click on any button change it's image (For normal state) to highlighted image for that particular button and set other 4 button's image to normal image...

mihirpmehta
@mihirpmehta,If i do that it will dispaly only one seconds. But i want to highlight the button till the next button is clicked.(similar tabbar)
Pugal Devan
above Logic is for that only... suppose for button1's normal state image11 is there and image12 is for highlighted... in button1's click event set button1's image to button12 (For normal state)... and for other 4 buttons change it's image to their respective normal state's image... It will definitely work... did you get my point..?
mihirpmehta
+1  A: 

You should be manipulating the image for selected state, not for highlighted state. Highlight will be unset on touch up or touch outside, as you have seen, whereas selected is persistent.

Paul Lynch
+1  A: 

It sounds like you should be using a UISegmentedControl with 5 segments instead of 5 buttons. It behaves this way already, a segment stays highlighted until you select a different one (unless you set the momentary property).

progrmr