首页 > 其他 > 详细

UISwitcher

时间:2017-09-23 12:08:38      阅读:274      评论:0      收藏:0      [点我收藏+]
 1 //同步属性和成员变量
 2 @synthesize mySwitch = _mySwitch;
 3 
 4 - (void)viewDidLoad {
 5     [super viewDidLoad];
 6 
 7     _mySwitch = [[UISwitch alloc]init];
 8     
 9     //宽高两个属性参数没有用,苹果自己定好了宽高
10     _mySwitch.frame = CGRectMake(100, 100, 40, 40);
11     
12    // _mySwitch.on = YES;
13     
14     //set方式
15     //[_mySwitch setOn:YES];
16     
17     [_mySwitch setOn:YES animated:YES];
18     
19     //设置开启状态时风格
20     //[_mySwitch setOnTintColor:[UIColor blueColor]];
21     
22     //圆钮
23     [_mySwitch setThumbTintColor:[UIColor redColor]];
24     //整体
25     [_mySwitch setTintColor:[UIColor blackColor]];
26     
27     [self.view addSubview:_mySwitch];
28     
29     
30     [_mySwitch addTarget:self  action:@selector(swchanged:) forControlEvents:UIControlEventValueChanged];
31     
32     
33 }
34 
35 -(void) swchanged:(UISwitch*) sw
36 {
37     if(sw.on)
38     {
39            NSLog(@"Sw open");
40     }
41     else
42     {
43         NSLog(@"Sw closed");
44     }
45     
46  
47 }

 

 

 

1 @interface ViewController : UIViewController
2 {
3     //定义一个开关控件
4     UISwitch* _mySwitch ;
5 }
6 
7 @property (retain,nonatomic) UISwitch* mySwitch;

 

UISwitcher

原文:http://www.cnblogs.com/vector11248/p/7580447.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!