16.UISwitch(开/关视图)
来源:互联网 发布:淘宝四件套床上用品 编辑:程序博客网 时间:2024/05/17 00:51
UISwitch继承于UIControl
UIControl 继承于UIView
1.初始化
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 0, 0)];
2 .设置属性
设置边框的颜色
mySwitch.tintColor = [UIColor redColor];
设置开启的颜色
mySwitch.onTintColor = [UIColor blueColor];
设置圆点的颜色
mySwitch.thumbTintColor = [UIColor greenColor];
设置开启状态 默认是NO
mySwitch.on = YES;
animated开启时候有动画效果
[mySwitch setOn:YES animated:YES];
UISwitch和UIButton一样继承UIControl 都可以触发点击方法
添加开关事件
[mySwitch addTarget:self action:@selector(mySwithOn:) forControlEvents:(UIControlEventTouchUpInside)];
3 .添加到窗口
[self.window addSubview:mySwitch];
4.释放
[mySwitch release];
实现开关事件
- (void)mySwithOn:(UISwitch *)mySwitch
{
判断是否开启
if (mySwitch.on) {
设置开启后效果
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”提示” message:@”确定开启” delegate:self cancelButtonTitle:@”确认” otherButtonTitles:@”取消”, nil];
[alertView show];
[alertView release];
NSLog(@”开启状态”);
}else{
设置关闭效果
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”提示” message:@”确认取消” delegate:self cancelButtonTitle:@”确认” otherButtonTitles:@”取消”, nil];
[alertView show];
[alertView release];
NSLog(@”关闭状态”);
}
}
- 16.UISwitch(开/关视图)
- IOS使用视图控制器和视图(二)通过 UISwitch 创建及使用开关
- iOS开发之基础视图— UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- UISwitch
- NSOrderedSame NSOrderedAscending NSOrderedDescending字符串枚举比较
- HDU5510 Bazinga KMP+剪枝
- 如何接入学历查询接口(附代码)
- 关于weka文件不能保存的问题
- ubuntu 14.04 安装mysql
- 16.UISwitch(开/关视图)
- FZU-Problem 2191 完美的数字
- iOS本地通知和远程通知
- 图像复原
- Android打包安装过程
- 单链表的程序实现
- 【黑马程序员】方法与数组
- 关于xcode7升级以后,无法archive,或者archive后xcode闪退的问题处理方案
- 【LeetCode OJ 007】Reverse Integer