UISwitch——开关控件
开关的可配置选项很少,一般用于处理布尔值。
下面给出一个小Demo,创建两个开关,开关一可以控制开关二的可用与否,两者的关系就相当于水闸与水龙头的关系。
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong) UISwitch *swicth1;
@property(nonatomic,strong) UISwitch *switch2;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UISwitch *swicth1 = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 0, 0)];
self.swicth1 = swicth1;
[swicth1 addTarget:self action:@selector(clickSwitch) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:swicth1];
UISwitch *switch2 = [[UISwitch alloc] initWithFrame:CGRectMake(100, 200, 0, 0)];
self.switch2 = switch2;
[switch2 addTarget:self action:@selector(clickSwitch) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:switch2];
}
- (void)clickSwitch {
//switch1控制switch2的可用与否
self.switch2.userInteractionEnabled = self.swicth1.on;
}
最新文章
- SAP CRM 客户控制器与数据绑定
- 【学习篇:他山之石,把玉攻】jquery实现调用webservice
- BZOJ 3144 [Hnoi2013]切糕 ——网络流
- Mysql数据库的使用总结之ERROR 1146 (42S02)
- Elasticsearch Javascript API增删改查
- NFS服务器
- java开发之多线程需要学习和理解的东西
- 【原创】MIPS·Verilog·FPGA
- 不错的轮播插件flexslider
- 1160 蛇形矩阵(codevs)
- POJ 1330 Nearest Common Ancestors LCA题解
- hadoop namespace
- jsp基础与提高(EL、JSTL)
- Visual Studio 2015 无法命中断点
- selenium+python之 辨识alert、window以及操作
- Tensorflow[LSTM]
- json和jsonp的使用区别
- HDU 3848 CC On The Tree(树形dp)
- java 创建过程
- Sql server 中关闭ID自增字段(SQL取消ID自动增长)