UISwitch控件
#pragma mark - 创建一个开关控件
-(void)creatOneSwitch{
//UISwitch控件的大小是固定的
UISwitch * oneSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(40, 40, 0,0)];
[self.view addSubview:oneSwitch];
//属性设置
oneSwitch.tintColor = [UIColor redColor];//关闭状态颜色
oneSwitch.onTintColor = [UIColor blueColor];//打开状态颜色
oneSwitch.thumbTintColor = [UIColor yellowColor];//中间原点颜色
oneSwitch.offImage = [UIImage imageNamed:@"off"];//In iOS 7, this property has no effect.
oneSwitch.onImage = [UIImage imageNamed:@"on"];//In iOS 7, this property has no effect.
oneSwitch.on = YES;//设置控制状态,默认为no;
BOOL isOn = oneSwitch.isOn;//获取控制状态
NSLog(@"isOn = %d",isOn);
//添加事件
[oneSwitch addTarget:self action:@selector(switchEvent:) forControlEvents:UIControlEventValueChanged];
}
//开关控件的点击事件
-(void)switchEvent:(UISwitch*)oneSwitch{
NSLog(@"点击了切换事件");
}