Uiswitch if placed in a uiview, then it will be based on the parent control uiview fixed size, no matter how you set the Uiswitch frame can not change its size, the solution is as follows:
-(void) Viewdidload {
[Super Viewdidload];
Do no additional setup after loading the view.
Self.view.backgroundColor = [Uicolor Graycolor];
UIView *mainview = [[UIView alloc] Initwithframe:cgrectmake (0, M, Kscreenwidth, 30)];
Mainview.backgroundcolor = [Uicolor Whitecolor];
[Self.view Addsubview:mainview];
Uiswitch *nameswitch = [[Uiswitch alloc] Initwithframe:cgrectmake (kscreenwidth/2.0, 0, 25, 15)];
Nameswitch.on = YES;
Nameswitch.transform = Cgaffinetransformmakescale (0.7, 0.6); Key code to change size
[Mainview Addsubview:nameswitch];
}
Add:
Initialization of 1.UISwitch
Uiswitch *switchview = [[Uiswitch alloc] Initwithframe:cgrectmake (54.0f, 16.0f, 100.0f, 28.0f)];
2. Set the initialization state of the Uiswitch
Switchview.on = yes;//setting is initially on side
Response to 3.UISwitch Events
[SwitchView addtarget:self Action: @selector (switchaction:) forcontrolevents:uicontroleventvaluechanged];