#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;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-13 20:52:00