I have 4 buttons in my iPhone application, which were added like this:
UIImage *button1Image = [UIImage imageNamed:@"friends.png"];
button1 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
self.button1.tag=102;
[button1 setImage:button1Image forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"friends_hvr.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
self.button1.frame = CGRectMake(90,5, 70,32);
[button1 addTarget:self action:@selector(friends:) forControlEvents:UIControlEventTouchUpInside];
I want to make my button state selected for some time so that I am changing the background when the button is selected, i.e., until the next button selected. But for me it is working only sometimes, in a blink. I need this to be persisted in the action. I was doing it like this:
-(void)friends:(id)sender
{
[button1 setSelected:YES];
Can anybody help me?
Try adding the line:
You were only using this image for the state where it was both selected and highlighted at the same time. (Yes, it’s confusing that or’ing those constants together produces the state where they are both active.)
Then just deselect the previously-selected button in your
friends:method.