读书人

08-UISwitch控件两种使用方法跟监听

发布时间: 2013-10-12 11:54:04 作者: rapoo

08-UISwitch控件两种使用方法和监听

?

?

二、通过拖拽方法使用UISwitch

1、往xib文件上拖拽一个UISwitch控件。

08-UISwitch控件两种使用方法跟监听

2、按alt+command + return键开启Assistant Editor模式,选中UISwitch控件,按住Control键,往ViewController.h拖拽

08-UISwitch控件两种使用方法跟监听

3、选Action方式

08-UISwitch控件两种使用方法跟监听

4、.m文件中实现switchAction 。刚才动态创建的时候也用到这个方法名称,可以先注释掉刚才的。

?

- (IBAction)switchAction:(id)sender { UISwitch *switchButton = (UISwitch*)sender; BOOL isButtonOn = [switchButton isOn]; if (isButtonOn) { showSwitchValue.text = @"是"; }else { showSwitchValue.text = @"否"; }}


运行就可以了。

读书人网 >移动开发

热点推荐