iOS OC C

Switch

920 发布: 2015/11/16 13:16 本文总阅读量

switch

- (void) switchIsChanged:(UISwitch *)paramSender{
   
  NSLog(@"Sender is = %@", paramSender);
   
  if ([paramSender isOn]){
      NSLog(@"The switch is turned on.");
  } else {
      NSLog(@"The switch is turned off.");
  }
   
}
 
- (void)viewDidLoad{
  [super viewDidLoad];
   
  self.view.backgroundColor = [UIColor whiteColor];
  self.mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 0, 0)];  
  [self.mySwitch setOn:YES];
  [self.view addSubview:self.mySwitch];
   
  [self.mySwitch addTarget:self action:@selector(switchIsChanged:)forControlEvents:UIControlEventValueChanged];
   
}