UISwitch控件
UISwitch *infoSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(20 , 200 , 20, 10)];
[infoSwitch setOn:YES];[infoSwitch addTarget:self action:@selector(switchClick:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:infoSwitch];
- (void)switchClick: (UISwitch *)sender {
UISwitch *buttonSwitch = (UISwitch *)sender;
BOOL isSwitchOn = buttonSwitch.isOn;
if (isSwitchOn) {
///what to do...
NSLog(@"open");
}else {
///what to do...
NSLog(@"close");
}
}

本文介绍了如何在iOS应用中使用UISwitch控件实现开关功能。通过实例代码展示了UISwitch的基本配置方法,包括设置初始状态、添加点击事件响应等,并解释了如何根据不同状态执行相应操作。
496

被折叠的 条评论
为什么被折叠?



