#pragma mark - 加载视图
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(20, 20, 0, 0);
self.mySwitch = [[UISwitch alloc] initWithFrame:frame];
//设置当前的状态是开启的
[self.mySwitch setOn:YES animated:YES];
//制定外观
//底色
self.mySwitch.onTintColor = [UIColor orangeColor];
//打开的底部颜色
self.mySwitch.tintColor = [UIColor blueColor];
//滑块颜色
self.mySwitch.thumbTintColor = [UIColor grayColor];
// self.mySwitch.onImage = //打开的图片
// self.mySwitch.offImage = //关闭的图片
[self.mySwitch addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.mySwitch];
}
#pragma mark - 做todo事件
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
-(IBAction)change:(id)sender{
UISwitch *swith = (UISwitch *)sender;
if(swith.isOn){
NSLog(@"打开");
}else{
NSLog(@"关闭");
}
}
UISwitch就是一个开关,只有开和关的状态
UISwitch
最新推荐文章于 2022-10-13 11:00:00 发布