// 1. 开关
- (void)switcher {
UISwitch * _switch=[[UISwitch alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
_switch.backgroundColor=[UIColor orangeColor];
//设置是否开启
_switch.on=NO;
//设置开启颜色
_switch.onTintColor=[UIColor greenColor];
//镂空颜色
_switch.tintColor=[UIColor brownColor];
//设置继承UIControll 可由用户操作
//添加事件
[_switch addTarget:self action:@selector(swithClicked:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_switch];
}
-(void)swithClicked:(UISwitch * )st
{
if (st.on) {
self.view.backgroundColor=[UIColor whiteColor];
}else{
self.view.backgroundColor=[UIColor blackColor];
}
}