zoukankan      html  css  js  c++  java
  • IOS--UISwitch的使用方法

    IOS--UISwitch的使用方法详细

     (2013-08-24 11:09:38)
    标签: 

    uiswitch

     

    switch

     

    选择控件

     

    ios

     

    it

    分类: iOS--UI

    // UISwitch的使用

        UISwitch *oneSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(20, 20, 0, 0)]; // 默认尺寸为79 * 27。

        oneSwitch.backgroundColor = [UIColor greenColor]; // 设置背景色

        oneSwitch.alpha = 1.0; // 设置透明度 范围在0.0-1.0之间 0.0是完全透明

        

        oneSwitch.onTintColor = [UIColor redColor]; // 在oneSwitch开启的状态显示的颜色 默认是blueColor

        oneSwitch.tintColor = [UIColor purpleColor]; // 设置关闭状态的颜色

        oneSwitch.thumbTintColor = [UIColor blueColor]; // 设置开关上左右滑动的小圆点的颜色

        

        // oneSwitch.on = YES; // // 设置初始状态 直接设置为on,你不回观察到它的变化

        [oneSwitch setOn:YES animated:YES]; // 设置初始状态,与上面的不同是当你看到这个控件的时候再开始设置为on,你会观察到他的变化

        

        

        oneSwitch.onImage = [UIImage imageNamed:@"min.png"]; // 打开状态显示的图片

        oneSwitch.offImage = [UIImage imageNamed:@"max.png"]; // 关闭状态下的图片

        

        [oneSwitch addTarget:self action:@selector(oneSwitchValueChanged:)forControlEvents:UIControlEventValueChanged]; // 添加事件监听器的方法

        // 添加到view并释放内存

        [self.view addSubview:oneSwitch];

        [oneSwitch release], oneSwitch = nil;

    #pragma mark - 实现UISwitch监听的方法

    - (void)oneSwitchValueChanged:(UISwitch *) sender {

        NSLog(@"%@", sender.isOn ? @"ON" : @"OFF");

    }

  • 相关阅读:
    L1-031 到底是不是太胖了
    L1-030 一帮一
    PyCharm--git配置
    websocket--python
    UDP--python
    TCP--python
    pytest--metadata
    pytest--xdist
    pytest--夹具
    pytest--变量
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4131998.html
Copyright © 2011-2022 走看看