I have to add radio buttons in my iPhone application. For that I have got radio button image which is of round in shape. Can I add that image as a subview? and Can I add tou
I just published an iOS Radio Button control to Cocoapods pod "DLRadioButton"
, for documentation and examples, please go to GitHub. Attached are screenshots for this control.
//define property of button
Declare Unchaked Image
- (void)viewDidLoad
{
[ButtonChaked setBackgroundImage:[UIImage imageNamed:@"UnChacked.png"] forState:UIControlStateNormal];
}
Chaked Image.
- (IBAction)ButtonChaked:(id)sender
{
if (ButtonChaked.selected ==YES)
{
[ButtonChaked setBackgroundImage:[UIImage imageNamed:@"UnChacked.png"] forState:UIControlStateSelected];
ButtonChaked.selected =NO;
}
else
{
[ButtonChaked setBackgroundImage:[UIImage imageNamed:@"Chaked.png"] forState:UIControlStateNormal];
ButtonChaked.selected = YES;
}
}
that's really used
There is no any RadioButton control in iPhone application.
Though you can check folliwing link for taking RadioButton.
Here we placed Two Images in place of RadioButtons.
http://www.developers-life.com/radio-buttons-in-iphone-application.html
Enjoy Coding........
IBOutlet UIButton *checkboxButtonMale;
IBOutlet UIButton *checkboxButtonFmale;
checkboxButtonFmale.tag = 3;
checkboxButtonMale.tag = 2;
(IBAction)checkboxGenderChecked:(id)sender{
UIButton *selectedButton = (UIButton *)sender;
UIButton *toggledButton;
if (selectedButton.tag == 2 ) {
toggledButton = checkboxButtonFmale;
}
else {
toggledButton = checkboxButtonMale;
} [toggledButton setSelected:NO];
[sender setSelected:YES];
}
If you have only "yes" or "no" options then use UISwitch.
For multiple type use the code below:
-(void)buttonPressed:(id)sender{
if([sender isSelectd])
//here change button image and set
[sender setSelected:NO];
}else{
//here change button image and set
[sender setSelected:YES];
}
remember, when you create the button don't forget to set the setSelected to NO.