-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUISwitch
38 lines (33 loc) · 1.29 KB
/
UISwitch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
简单创建一个UISwitch,然后调用了theSymbleOfSwitch:函数来判断switch的开关状态
*/
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//初始化一个switch
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake
(100.0f, 100.0f, 0.0f, 0.0f)];
[mySwitch addTarget:self
action:@selector(theSymbleOfSwitch:)
forControlEvents:UIControlEventValueChanged]; //这里的UIControlEventValueChanged以后经常会用
[self.view addSubview:mySwitch];
}
-(void) theSymbleOfSwitch:(UISwitch *)paramSender //判断switch的开关状态
{
NSLog(@"Sender is = %@",paramSender);
if ([paramSender isOn]) {
NSLog(@"the Switch is on");
}
else
{
NSLog(@"the Switch is off");
}
}
/*
输出结果:
2013-10-11 10:09:35.402 WillSendToGithub[1109:a0b] Sender is = <UISwitch: 0xa2584a0; frame = (100 100; 51 31); layer = <CALayer: 0xa259da0>>
2013-10-11 10:09:35.403 WillSendToGithub[1109:a0b] the Switch is on
2013-10-11 10:09:45.121 WillSendToGithub[1109:a0b] Sender is = <UISwitch: 0xa2584a0; frame = (100 100; 51 31); layer = <CALayer: 0xa259da0>>
2013-10-11 10:09:45.121 WillSendToGithub[1109:a0b] the Switch is off
*/