08-UISwitch控件两种使用方法和监听
?
?
二、通过拖拽方法使用UISwitch
1、往xib文件上拖拽一个UISwitch控件。
2、按alt+command + return键开启Assistant Editor模式,选中UISwitch控件,按住Control键,往ViewController.h拖拽
3、选Action方式
4、.m文件中实现switchAction 。刚才动态创建的时候也用到这个方法名称,可以先注释掉刚才的。
?
- (IBAction)switchAction:(id)sender { UISwitch *switchButton = (UISwitch*)sender; BOOL isButtonOn = [switchButton isOn]; if (isButtonOn) { showSwitchValue.text = @"是"; }else { showSwitchValue.text = @"否"; }}
运行就可以了。