Home Tutorial Iphone Examples iPhone SelectButton

 
 

Share on Google+Share on Google+
iPhone SelectButton
Posted on: September 25, 2009 at 12:00 AM
Advertisement
In this tutorial we will learn how to set two image button i.e. when the button is selected the image of the button changes and deselect the button image also change so that you can know when button selected.

iPhone SelectButton

In this tutorial will learn how to set two image button options i.e. Select Button Image and deselect Image button. When the Select button is clicked or selected the image of the button changes and deselect the button image also change so that you can know when button selected. This action trigger is done using Interface Builder, will add button and on that button will set image on default and also on selected and will write the code for that. So, we will create variable and also the action for the button. This project is based on View Based Application, and coding will be done in view Controller file. After making variables and the action for the button, connect it in Interface Builder.

Final Image will look like this:

iphone select button options

My project name is selectAndDeselect and is based on view application. In view controller we will create variable for the button and will write the action for that so that when the button is clicked or pressed will change the image of the button. For that purpose we have to take on Boolean variable to check the condition.

Add this to .h file:

IBOutlet UIButton *selectButton;

    BOOL ButtonSelected;

-(IBAction)Selected:(id)sender;

In .m file will write the method for the action and in that check the condition based on the boolean variable if equal to zero then select button otherwise default button or deselect the button and after this will add boolean in view did load method.

Add this to .m file:

-(IBAction)Selected:(id)sender

{

    if (ButtonSelected == 0)

    {

        [selectButton setSelected:YES];

        ButtonSelected = 1;

    }else

    {

        [selectButton setSelected:NO];

        ButtonSelected = 0;

    }

}

- (void)viewDidLoad

{

    [super viewDidLoad];

 ButtonSelected == 0;

}

After Creating the variable and writing the action of the button in .h file, we have to connect the variable into the Interface Builder and also set the Image on the button before doing this set the button as custom and then set the image of the button (select and default) as shown below.

Make connections as shown:

 

Finally press Build And Go button.

Download Here

Advertisement

Related Tags for iPhone SelectButton:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 25, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com