IOS UIswitch基本使用
程序员文章站
2022-07-13 16:34:08
...
- (void)viewDidLoad {
[super viewDidLoad];
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat switchScreenSpace = 39;
self.rightSwitch = [[UISwitch alloc] init];
CGRect frame = self.rightSwitch.frame;
frame.origin = CGPointMake(switchScreenSpace, 98);
self.rightSwitch.frame = frame;
self.rightSwitch.on = TRUE;
[self.rightSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.rightSwitch];
self.leftSwitch = [[UISwitch alloc] init];
frame = self.leftSwitch.frame;
frame.origin = CGPointMake(screen.size.width - (frame.size.width + switchScreenSpace), 98);
self.leftSwitch.frame = frame;
self.leftSwitch.on = TRUE;
[self.leftSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview: _leftSwitch];
}
- (void)switchValueChanged: (id)sender{
UISwitch *whichSwitch = (UISwitch *)sender;
BOOL setting = whichSwitch.isOn;
[_leftSwitch setOn:setting animated:TRUE];
[_rightSwitch setOn:setting animated:TRUE];
}
上一篇: 输入年月日判断是该年的第几天
下一篇: 公司注册步骤包含的内容,公司注册步骤
推荐阅读