"iOS Dev-12" uiswitch switch control properties description and get switch status and respond

Source: Internet
Author: User

(1) The size of the Uiswitch is also fixed, not with the size of our frame to change, but also cut into rounded corners, set the background to reveal the background is a rectangle.


(2) Uiswitch background image setting is invalid, that is, we can only set the color, not with the picture when the background, although the experiment of a very small picture, is not. May need to be implemented with third-party classes.


(3) Uiswitch can also increase the Addtarget: method to obtain the action of the value change, thus reacting to the response.


(4). The Ison property is special, cannot set the value, because is the elder brother Getter method, is not the setter method, therefore can only obtain the value, for example determines whether opens, generally uses in the IF statement.


-(void) Viewdidload {//Instantiate a switch control Uiswitch *swi1=[[uiswitch Alloc]init]; Set the location and size to find that the size is invalid.    That is, the switch control size is not affected, or so swi1.frame=cgrectmake (30, 100, 300, 80);    Setting the background, it is found that the size of the box set above is really invalid, because the background is only as large as the control, not set so large, and the control is rounded swi1.backgroundcolor=[uicolor redcolor];    Set the background color on the side, the default is Green Swi1.ontintcolor=[uicolor Yellowcolor];    Set the background color on the off side, the default is gray, found that the off background color is actually the control "border" color Swi1.tintcolor=[uicolor Purplecolor];    Set slider color Swi1.thumbtintcolor=[uicolor greencolor]; Swi1.onimage=[uiimage imagenamed:@ "1.png"];//invalid swi1.offimage=[uiimage imagenamed:@ "logo.png"];//Invalid//    Set to open the disease set animation form appears, of course, can also be directly used [Swi1 Seton:yes];    [Swi1 Seton:yes Animated:yes]; The switch control is turned off by default, and the Seton can be turned on by default, so it has an open action when it is displayed, but this action does not send a message, that is, we do an experiment to get an action for "value change", that is, the value changes, turn the output "on", turn off the output " Off "//Discover the first time there is no output on, we ourselves manually from off to on and on and off///So this Seton is an open action, but we can think of it as being built-in, we can't see this action, so we can't catch it, but here we practice getting value change disease benefit Use ISON to do the corresponding operation [Swi1 addtarget:self action: @selector (getValue1:) Forcontrolevents:uicontroleventvaluechanGED];    IsOn is a getter method, so can not be assigned, that is, can not use Swi.ison=yes, can only obtain the current results, generally used to determine whether the open state if (Swi1.ison) {NSLog (@ "It is on");    } [Self.view Addsubview:swi1];    [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.}    -(void) GetValue1: (ID) sender{uiswitch *swi2= (Uiswitch *) sender;    if (Swi2.ison) {NSLog (@ "on");    }else{NSLog (@ "Off"); }}


"iOS Dev-12" uiswitch switch control properties description and get switch status and respond

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.