当前位置: 代码迷 >> 综合 >> UISwitch 开关
  详细解决方案

UISwitch 开关

热度:71   发布时间:2023-12-17 01:08:43.0

开关

UISwitch *swt = [[UISwitch alloc] initWithFrame:CGRectMake(0, 30, 100, 50)];UIImage *on = [UIImage imageNamed:@"smiley_grin_30"];UIImage *off = [UIImage imageNamed:@"smiley_sad_30"];//设置on和off图片,7无效swt.onImage = on;swt.offImage = off;[swt setOn:YES animated:YES];[swt addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
- (void)change:(UISwitch *)swt
{//获取开关状态//swt.isOn == YES == on//swt.isOn == NO == offif (swt.isOn){NSLog(@"开");}else{NSLog(@"关");}
}