zoukankan      html  css  js  c++  java
  • UISwitch

    1、Switch 的创建

    // 实例化 switch 对象,switch 的大小是由系统固定的
    UISwitch *switch1 = [[UISwitch alloc] init];
    
    // 将 sw 添加到 view
    [self.view addSubview:switch1];
    

    2、Switch 的设置

    // 设置位置
    switch1.center = self.view.center;
    
    // 设置 tag 值
    switch1.tag = 100;
    
    // 设置外边框颜色
    switch1.tintColor = [UIColor redColor];
    
    // 设置滑块的颜色
    switch1.thumbTintColor = [UIColor blueColor];
    
    // 设置 on 时的颜色
    /*
    默认为绿色
    */
    switch1.onTintColor = [UIColor orangeColor];
    
    // 设置当前的开关状态
    switch1.on = YES;
    
    // 获取当前的开关状态
    BOOL isOn = switch1.isOn;
    
    // 添加点击触发事件
    [switch1 addTarget:self action:@selector(switchClick:) forControlEvents:UIControlEventValueChanged];
    
  • 相关阅读:
    133
    132
    131
    130
    129
    128
    2019.10.16考试解题报告
    2019.10.15考试解题报告
    洛谷 P1352 没有上司的舞会
    2019.10.13考试解题报告
  • 原文地址:https://www.cnblogs.com/CH520/p/9413477.html
Copyright © 2011-2022 走看看