0

Possible Duplicate:
Change Label of UISWitch

How to create uiswitch with yes/no in ios6 xcode 4.5.Tried customizing a switch but did not achieve the result. Any help would be greatly appreciated.Thanks in advance.

Community
  • 1
  • 1
Jason Wood
  • 737
  • 1
  • 13
  • 22

1 Answers1

1

Make a UISwitch Control. Then add an action which listens to the ValueChanged of the control. Remember to add the UISwitch to your view at the correct placement, here i am just making 40 x 40 switch.

UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[switchControl addTarget:self action:@selector(switchTapped:) forControlEvents:UIControlEventValueChanged];

In the switchTappedMethod, you find the state with this value:

-(void) switchTapped: (id) sender {
UISwitch *switchControl = (UISwitch*) sender;
BOOL value = switchControl.isOn;
}
bogen
  • 9,954
  • 9
  • 50
  • 89