开发者

How to highlight the button untill the next view is changed in iphone?

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:@"Cont开发者_运维问答entColor.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.


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.


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...


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).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜