UI_UISwitch控件

#pragma mark - 创建控件 UISwitch

- (void)createSwitch
{
    UISwitch *aSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(50, 150, 0, 0)];

    [self addSubview:aSwitch];
    [aSwitch release];

    // 添加绑定事件
    [aSwitch addTarget:self action:@selector(aSwitchAction:) forControlEvents:UIControlEventValueChanged];
    // 设置开关为打开状态
    aSwitch.on = YES;
}


- (void)aSwitchAction:(UISwitch *)sender
{
    NSLog(@"aSwitch");
    if (sender.isOn) {
        self.view.hidden = NO;
    } else {
        self.view.hidden = YES;
    }


}

你可能感兴趣的:(ios,UI,事件,mark,UISwitch)