#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;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/yadong_zhao/article/details/46777803