UISwitch
来源:互联网 发布:美微网络电视看香蕉 编辑:程序博客网 时间:2024/05/05 21:18
UISwitch,即开关。
1、创建
- UISwitch* mySwitch = [[ UISwitch alloc]initWithFrame:CGRectMake(200.0,10.0,0.0,0.0)];
2、显示控件
[ parrentView addSubview:mySwitch];//添加到父视图
self.navigationItem.titleView = mySwitch;//添加到导航栏
3、开关状态
1)获取开关状态
- BOOL switchStatus = mySwitch.on;
2)设置开关状态
[ mySwitch setOn:YES animated:YES];
4、通知
想要在开关状态切换时收到通知,可以用UIControl类的addTarget方法为UIControlEventValueChanged事件添加一个动作。
- [ mySwitch addTarget: self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
- - (void) switchValueChanged:(id)sender{
- UISwitch* control = (UISwitch*)sender;
- if(control == mySwitch){
- BOOL on = control.on;
- //添加自己要处理的事情代码
- }
- }
5、其他要点
开关打开和关闭的图像
onImage\offImage
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- Cocos2d-x 实现时钟
- 霍夫变换(Hough Transform)直线检测
- Eclipse中快捷键
- HDU 1166(敌兵布阵)
- 设计模式之命令模式,command
- UISwitch
- Salesforce travel
- JS 将 格式化的时间 转换成 时间戳
- 安装vs2010 MSDN
- Mutex和内存可见性
- android自定义view–绘制顺序及相关原理
- Android Info类的总结
- 设计模式之访问者模式,visitor
- ASP.NET TextBox 当鼠标点击后清空默认提示文字