UISwitch
来源:互联网 发布:手机主板检测软件 编辑:程序博客网 时间:2024/04/30 12:19
UISwitch是左右滑动关闭,或开启的开机按钮视图控件
一基本属性
// 1 初始化UISwitch *switchView = [[UISwitch alloc] init];// 2 添加到父视图[self.view addSubview:switchView];// 3 设置原点坐标及大小(通常情况下只设置原点坐标,大小默认(frame = (0 0;51 31)))// 3-1 方法1// switchView.frame = CGRectMake(50.0,50.0,51.0,31.0); // 3-2 方法2CGRect rect = switchView.frame;rect.origin.x = 50.0;rect.origin.y = 50.0;switchView.frame = rect;NSLog(@"switchView %@",switchView);初始化,开启后默认背景颜色为绿色
二其他属性
// 1 设置开启后的背景颜色switchView.onTintColor = [UIColor redColor];// 2 设置关闭后的边框颜色switchView.tintColor = [UIColor orangeColor];// 3 设置拔弄开关的颜色switchView.thumbTintColor = [UIColor purpleColor];// 4 设置开关状态,默认是NO,即关闭switchView.on = NO;
三添加响应方法
[switchView addTarget:self action:@selector(showLabel:) forControlEvents:UIControlEventValueChanged]; // 1 设置Lable// 1.1 初始化UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 100.0, (CGRectGetWidth(self.view.bounds) - 50.0 * 2), 40.0)];// 1.2 将添加到父视图[self.view addSubview:label];// 1.3 设置背景颜色label.backgroundColor = [UIColor redColor];// 1.4 添加显示内容label.text = @"我显示出来了";// 1.5 tag值label.tag = 1000;// 1.6 透明度label.alpha = 0.0;
// 显示或隐藏标签- (void)showLabel:(UISwitch *)switchView{ BOOL isShow = switchView.on; UILabel *label = (UILabel *)[self.view viewWithTag:1000.0]; if (isShow) { label.text = @"我显示出来了"; label.alpha = 1.0; } else { label.text = @"我要隐身了"; [UIView animateWithDuration:1.2 animations:^{label.alpha = 0.5 ; } ]; }}
1 0
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- 自定义ToolBar
- IOS OPENGL ES 之EAGLContext上下文配置
- (七) spring_Bean的作用域
- acm之贪心算法题目6
- 理解postgresql数据表与其对应的数据文件关系
- UISwitch
- 欢迎使用CSDN-markdown编辑器
- [bzoj2733][HNOI2012]永无乡
- 持久层内存溢出
- Flask: Ajax 设置Access-Control-Allow-Origin实现跨域访问;Ajax页面底部自动加载
- acm之贪心算法题目7
- 剑指offer37--找出数组中只出现1次的两个数
- R通过RJDBC连接外部数据库
- 程繁问于乐