views:

40

answers:

1

Hi all,

I have a UIButton (Info Dark) which opens a small box on click. Is it possible to change the style/state the button so that the buttons appears highlighted or something like this as long as the box is open? Or do I have to use own background images for the button?

A: 

Try this:

[yourButton setBackgroundImage:[UIImage imageNamed:@"highlighted_image.png"] forState:UIControlStateHighlighted];
[yourButton setBackgroundImage:[UIImage imageNamed:@"highlighted_image.png"] forState:UIControlStateSelected];

and when you close that box you can put another picture on your button to look normal (not highlighted) like this:

[yourButton setBackgroundImage:[UIImage imageNamed:@"oldPicture_notHighlighted.png"] forState:UIControlStateNormal];
Jeff Norman
Hi Jeff, thanks for the quick answer. The only problem is that the button does not stay in the highlighted or selected state when it is clicked the state is only changed while the button is touched.
Crazer
Got it: [buttonClicked setSelected:YES];
Crazer
Ahh, now I see your comment, I forgot to tell you that, if you want your button to remain with the highlighted image you must set it to selected.
Jeff Norman