开关的可配置选项很少,一般用于处理布尔值。

  下面给出一个小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;

}

最新文章

  1. SAP CRM 客户控制器与数据绑定
  2. 【学习篇:他山之石,把玉攻】jquery实现调用webservice
  3. BZOJ 3144 [Hnoi2013]切糕 ——网络流
  4. Mysql数据库的使用总结之ERROR 1146 (42S02)
  5. Elasticsearch Javascript API增删改查
  6. NFS服务器
  7. java开发之多线程需要学习和理解的东西
  8. 【原创】MIPS·Verilog·FPGA
  9. 不错的轮播插件flexslider
  10. 1160 蛇形矩阵(codevs)
  11. POJ 1330 Nearest Common Ancestors LCA题解
  12. hadoop namespace
  13. jsp基础与提高(EL、JSTL)
  14. Visual Studio 2015 无法命中断点
  15. selenium+python之 辨识alert、window以及操作
  16. Tensorflow[LSTM]
  17. json和jsonp的使用区别
  18. HDU 3848 CC On The Tree(树形dp)
  19. java 创建过程
  20. Sql server 中关闭ID自增字段(SQL取消ID自动增长)

热门文章

  1. mysql Group By
  2. Linux + Apache + PHP 环境搭建
  3. The Accumulation of Capital
  4. 动态规划2-----hdu1069
  5. 【摘自网络】dll库和lib库有什么区别
  6. BZOJ 1196 二分答案+并查集
  7. angular 实现modal windows效果(即模态窗口,半透明的遮罩层),以及bootstrap(css,components,js)的初步学习
  8. android中设置ListView的选中的Item的背景颜色
  9. webapp之路--之ios上图标
  10. GPU