UISwitch简单介绍
UISwitch是个好东西,话不多说,上代码
UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(50, 100, 0, 0)]; [switchButton setOn:YES]; [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:switchButton]; [switchButton release]; -(void)switchAction:(id)sender { UISwitch *switchButton = (UISwitch*)sender; BOOL isButtonOn = [switchButton isOn]; if (isButtonOn) { NSLog(@"开关打开"); }else { NSLog(@"开关关闭"); } }