• UISwitch


    UISwitch继承于UIControl,通常被叫做开 关
     
    初始化:
     
    - (instancetype)initWithFrame:
    //这个frame是没有意义的,系统的开关控件⼤⼩是确定的。(系统默认值)
     
    onTintColor //设置开关开启状态时的颜⾊
    tintColor //设置开关风格颜⾊
    thumbTintColor //设置开关按钮颜⾊
     
    onImage //设置开关开启状态时的图⽚(注意:在IOS7后不再起任何作⽤)
    offImage //设置开关关闭状态时的图⽚(注意:在IOS7后不再起任何作⽤)
    on //开关的状态
    setOn:animated: //⼿动设置开关状态
     
    //创建一个UISwitch 这里的frame只有origin起作用,size使用系统默认大小
        UISwitch *firstSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 0, 0)];
       
        firstSwitch.center = CGPointMake(self.view.center.x, 110);
       
        //设置开关开启状态时的颜色
        firstSwitch.onTintColor = [UIColor lightGrayColor];
       
        //设置开关风格颜色
        firstSwitch.tintColor = [UIColor blackColor];
       
        //设置开关按钮颜色
        firstSwitch.thumbTintColor = [UIColor orangeColor];
       
        //设置开关开启状态时的图片
        firstSwitch.onImage = [UIImage imageNamed:@"mm.JPG"];
       
        //开关的状态
        firstSwitch.on = NO;
     
        //手动设置开关状态
    //    [firstSwitch setOn:YES animated:NO];
       
        [firstSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
       
        [self.view addSubview:firstSwitch];
        [firstSwitch release];
     
     
    - (void)switchAction:(UISwitch *)mySwitch {
        if (mySwitch.on == YES) {
            NSLog(@"开启");
        } else {
            NSLog(@"关闭");
        }
    }
  • 相关阅读:
    windows窗体中的一些事。。。
    数据库报错问题
    Winform程序调用WebService连接数据库心得
    浅谈RichTextBox在Windows Phone开发中的应用 [WP开发]
    WP7 独立存储
    安装 Visual Studio Async CTP
    C#中的弱引用(WeakReference)
    WP7开发积累
    2011.11.15
    c# 计算时间间隔
  • 原文地址:https://www.cnblogs.com/Walking-Jin/p/5210857.html
Copyright © 2020-2023  润新知