Tuesday, 19 June 2012

How to set checkbox in iphone sdk?

if u want to choose only one selected of twos using following line of code......

 IBOutlet UIButton *btnCheckBox1;
    IBOutlet UIButton *btnCheckBox2;

 btnCheckBox1.tag = 1;
    btnCheckBox2.tag = 2;
[btnCheckBox1 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
     [btnCheckBox2 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];

-(IBAction)btnCheckboxClicked:(id)sender{
 UIButton *selectedButton = (UIButton *)sender;
    UIButton    *toggledButton;
   
    if (selectedButton.tag == 1 ) {
        toggledButton =    btnCheckBox1;
         [btnCheckBox1 setImage:[UIImage imageNamed:@"active-checkbox.png"] forState:UIControlStateNormal];
        strType = lblEmployee.text;
    }
    else {
        [btnCheckBox1 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
    }
    if (selectedButton.tag == 2 ) {
        toggledButton =    btnCheckBox2;
        [btnCheckBox2 setImage:[UIImage imageNamed:@"active-checkbox.png"] forState:UIControlStateNormal];
        strType = lblEmployers.text;
    }
    else {
        [btnCheckBox2 setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];

    }
    [toggledButton    setSelected:NO];
    [sender setSelected:YES];
}

1 comment:

  1. wow that post is nice and if u have some code then please share with me i m waiting for yours the next post
    thanks

    -----------------------------------------------------------------
    iPhone 5 App Development And
    iPad Application Developer

    -------------------------------------------------------------------------------

    ReplyDelete