The following simple way to create radio button in your iOS app follow two steps.
Step1- Put this code in your in viewDidLoad or any other desired method
[_mrRadio setSelected:YES];
[_mrRadio setTag:1];
[_msRadio setTag:1];
[_mrRadio setBackgroundImage:[UIImage imageNamed:@"radiodselect_white.png"] forState:UIControlStateNormal];
[_mrRadio setBackgroundImage:[UIImage imageNamed:@"radioselect_white.png"] forState:UIControlStateSelected];
[_mrRadio addTarget:self action:@selector(radioButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[_msRadio setBackgroundImage:[UIImage imageNamed:@"radiodselect_white.png"] forState:UIControlStateNormal];
[_msRadio setBackgroundImage:[UIImage imageNamed:@"radioselect_white.png"] forState:UIControlStateSelected];
[_msRadio addTarget:self action:@selector(radioButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
Step2- Put following IBAction method in your class
-(void)radioButtonSelected:(id)sender
{
switch ([sender tag ]) {
case 1:
if ([_mrRadio isSelected]==YES) {
// [_mrRadio setSelected:NO];
// [_msRadio setSelected:YES];
genderType = @"1";
}
else
{
[_mrRadio setSelected:YES];
[_msRadio setSelected:NO];
genderType = @"1";
}
break;
case 2:
if ([_msRadio isSelected]==YES) {
// [_msRadio setSelected:NO];
// [_mrRadio setSelected:YES];
genderType = @"2";
}
else
{
[_msRadio setSelected:YES];
[_mrRadio setSelected:NO];
genderType = @"2";
}
break;
default:
break;
}
}