@interface ViewController ()
{
UISwitch *aSwitch;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
aSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(10,50,100,40)];
[self.view addSubview:aSwitch];
[aSwitch addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];
aSwitch.onTintColor = [UIColor orangeColor];
aSwitch.tintColor = [UIColor redColor];
aSwitch.thumbTintColor = [UIColor grayColor];
aSwitch.on = NO;
}
- (void)click:(UISwitch *)aSwitch{
NSLog(@"%d",aSwitch.on);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[aSwitch setOn:!aSwitch.isOn animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
UISwitch
最新推荐文章于 2022-03-21 11:03:41 发布