zoukankan      html  css  js  c++  java
  • 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;

    }

  • 相关阅读:
    hdu 2490 队列优化dp
    poj 1836 LIS变形
    hdu 3410 单调栈
    51nod 1437
    51nod 1215 单调栈/迭代
    51nod 1102 单调栈
    51nod 1272 思维/线段树
    51nod 1279 单调栈
    SpringMVC收藏
    今天接触枚举类型,感觉是C里面应该才有的东西
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4727447.html
Copyright © 2011-2022 走看看