-
(
void
)viewDidLoad
{
02.
03.
UISwitch
*swi1=[[UISwitch alloc]init];
04.
05.
swi1.frame=CGRectMake(
30
,
100
,
300
,
80
);
06.
07.
swi1.backgroundColor=[UIColor
redColor];
08.
09.
swi1.onTintColor=[UIColor
yellowColor];
10.
11.
swi1.tintColor=[UIColor
purpleColor];
12.
13.
swi1.thumbTintColor=[UIColor
greenColor];
14.
swi1.onImage=[UIImage
imageNamed:@
"1.png"
];
15.
swi1.offImage=[UIImage
imageNamed:@
"logo.png"
];
16.
17.
[swi1
setOn:YES animated:YES];
18.
19.
20.
21.
22.
23.
[swi1
addTarget:self action:
@selector
(getValue1:)
forControlEvents:UIControlEventValueChanged];
24.
25.
26.
if
(swi1.isOn)
{
27.
NSLog(@
"It
is On"
);
28.
}
29.
30.
[self.view
addSubview:swi1];
31.
[
super
viewDidLoad];
32.
33.
}
34.
35.
-(
void
)getValue1:(id)sender{
36.
UISwitch
*swi2=(UISwitch *)sender;
37.
if
(swi2.isOn)
{
38.
NSLog(@
"On"
);
39.
}
else
{
40.
NSLog(@
"Off"
);
41.
}
42.
}