UISwitch 开关控件

作者: 阿年同学 | 来源:发表于2016-07-21 14:27 被阅读170次

只是用于处理布尔值。

_mainSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
/*
 CGRectZero 是高度和宽度为0,位于(0,0)的矩形常量。
 需要创建边框但是不确定边框大小或位置时,可使用此常量。
 */

//位于正中央
_mainSwitch.center = self.view.center;

[self.view addSubview:_mainSwitch];

//关闭(OFF)颜色为红,开启(ON)颜色为蓝
_mainSwitch.tintColor = [UIColor redColor];
_mainSwitch.onTintColor = [UIColor blueColor];

//设置滑块颜色
_mainSwitch.thumbTintColor = [UIColor yellowColor];

//开关按钮发生变化时调用方法
[_mainSwitch addTarget:self action:@selector(switchState:) forControlEvents:UIControlEventValueChanged];


- (void)switchState:(UISwitch *)sender
{
    if (_mainSwitch.isOn) {
        NSLog(@"开卡丁车");
    } else {
        NSLog(@"芝麻关关关门");
    }
}
UISwitch开关动态图

相关文章

  • UISwitch和UIStepper

    UISwitch UISwitch(开关控件):提供了一个简单的开/关UI元素,类似于传统的物理开关,开关的可配置...

  • 关于iOS中UIControl的介绍

    UIKit提供了一组控件:UISwitch开关、UIButton按钮、UISegmentedControl分段控件...

  • UIControl

    UIKit提供了一组控件:UISwitch开关、UIButton按钮、UISegmentedControl分段控件...

  • UIKit的控件

    UIKit提供了一组控件:UISwitch开关、UIButton按钮、UISegmentedControl分段控件...

  • IOS开关控件,分段控件和滑块控件的使用方法

    那么我们将如何使用代码来实现开关控件,分段控件和滑块控件,将是我们今天的主要学习内容。 开关控件UISwitch ...

  • UISwitch 开关控件

    只是用于处理布尔值。

  • 开关控件 UISwitch

    *之前,在一个控件里访问另一个控件的内容,要把另一个控件提到全局类里面;现在有个新技巧,通过tag来区分控件(通过...

  • UISwitch 开关控件

    改变大小需要设置transform 注意:调试 一下Switch的�x、y,以改变比例transform

  • UIController

    UIKit提供了一组控件:UISwitch开关、UIButtonbutton、UISegmentedCon...

  • 哇 UISwitch开关控件的点击事件

    1.UISwitch:开关控件,继承与UIControl 2.创建UISwitch 3.开辟空间并指定位置和大小 ...

网友评论

    本文标题:UISwitch 开关控件

    本文链接:https://www.haomeiwen.com/subject/poybjttx.html