1.UISwitch的初始化
UISwitch *switchView = [[UISwitch alloc]initWithFrame:CGRectMake(0,0,50,30)];
2.设置UISwitch的初始化状态
switchView.on = YES;
3.事件触发
[switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];  // 开关事件切换通知
[self.view addSubview: switchView];
-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButtonisOn];
    if (isButtonOn) {
        NSLog(@"开");
    }else {
        NSLog(@"关");
    }
}