An example of how IOS changes uiswitch size

Source: Internet
Author: User

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];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.