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 == off
if (swt.isOn)
{
NSLog(@"开");
}
else
{
NSLog(@"关");
}
}