On the introduction of Swift development: switch (Uiswitch)

Source: Internet
Author: User

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)

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.