NoviceDeveloper
NoviceDeveloper

Reputation: 225

How to make selected button highlighted?

I have four buttons. I want that selected button keep highlighted till other button is selected. After that other button gets highlighted and first button unhighlighted.

- (void)doHighlight:(UIButton*)b {

   [b setHighlighted:YES];  

 }
-(IBAction)sizeBtnClicked:(UIButton*)btn{

     [self performSelector:@selector(doHighlight:) withObject:btn afterDelay:0];

}

My problem is after selecting other button first button does not unhighlight.please guide me how to do it.

Upvotes: 0

Views: 303

Answers (3)

Ankit Srivastava
Ankit Srivastava

Reputation: 12405

declare a variable button tempBtn in your .h , alloc it and then perform this.

-(IBAction)sizeBtnClicked:(UIButton*)btn{
         [tempBtn setHighlighted:NO];
         [btn setHighlighted:YES];
         tempBtn=btn ;
        [self performSelector:@selector(doHighlight:) withObject:btn afterDelay:0];

    }

Upvotes: 1

shivangi
shivangi

Reputation: 187

In nib file you can change a image for button selection in inspector

Upvotes: 0

Hanon
Hanon

Reputation: 3927

You simply get the reference of last selected button and then in the sizeBtnClicked, set the highlighted property of last selected button to NO.

Upvotes: 0

Related Questions