-(void)viewDidLoad{

[super viewDidLoad];

self.view.backgroundColor=[UIColor whiteColor];

switch1_=[[UISwitch alloc] init];

switch1_.center=CGPointMake(100,50);

//默认设置为ON

switch1_.on=YES;

//开关时调用switchDidChange方法

[switch1_ addTarget:self action:@selector(switchDidChange) forControlEvents:UIEventValueChanged];

[self.view addSubview:switch1_];


switch2_=[[UISwitch alloc] init];

switch2_.center=CGPointMake(100,100);

switch2_.on=NO;

[self.view addSubview:switch2_];

}


-(void)switchDidChange{

//switch1_变化后switch2_也一起变化

[switch2_ setOn:!switch2_.on animated:YES];

}