reprint Please declare source: http://blog.csdn.net/jinnchang/article/details/44407193
1. UIButton Overviewinheritance: Uiswitch, Uicontrol, UIView
2. Control style
3. Examples of Use
var Mybutton:uibutton?var myswitch:uiswitch?override func viewdidload () {Self.mybutton = Uibutton.buttonwithtype (. System) as? UIButton self.mybutton!. frame = CGRectMake (SELF.VIEW.FRAME.WIDTH/2-$, self.mybutton!, Max). Settitle ("Change state", ForState:UIControlState.Normal) self.mybutton!. AddTarget (Self, Action: "Buttonaction", forControlEvents:UIControlEvents.TouchUpInside) Self.myswitch = Uiswitch (f Rame:cgrectmake (SELF.VIEW.FRAME.WIDTH/2-(), (+), self.myswitch!). On = True self.myswitch!. Ontintcolor = Uicolor.lightgraycolor () self.myswitch!. Tintcolor = Uicolor.greencolor () self.myswitch!. Thumbtintcolor = Uicolor.blackcolor () self.myswitch!. AddTarget (Self,action:selector ("Switchchange:"), forControlEvents:UIControlEvents.ValueChanged)//EXTENSION: You can also set the Onimage, offimage to add a picture Self.view.addSubview (self.mybutton!) Self.view.addSubview (self.myswitch!)} The button corresponds to the event func buttonaction () {if self.myswitch!. on{priNtln ("Switch is on") self.myswitch!. SetOn (False, Animated:true)}else{println ("Switch is Off") self.myswitch!. SetOn (True, animated:true)}}///switch Control event func Switchchange (switchstate:uiswitch) {if Switchstate.on {println ("Switch is on")} else {println ("Switch is Off")}}
4. ConclusionProject on Github address: uiswitchsample
Article last updated: March 18, 2015 10:58:09. The resources are as follows:
UIKit User Interface catalog:switches
Uiswitch Class Reference
On the introduction of Swift development: switch (Uiswitch)