Swift开关按钮(UISwitch)的用法

import UIKit

class ViewController: UIViewController        ,UITextFieldDelegate,UITextViewDelegate,UIActionSheet  Delegate,UIAlertViewDelegate{
var uiswitch:UISwitch!;
override func viewDidLoad() {
    super.viewDidLoad()

    uiswitch = UISwitch()
    uiswitch.frame = CGRectMake(10, 230, 200, 30)
    uiswitch.on = true
    uiswitch.addTarget(self, action: Selector("switchDidChange"), forControlEvents: UIControlEvents.ValueChanged)
    self.view.addSubview(uiswitch)

  }

func switchDidChange(){
    
   print(uiswitch.on)
   
}

}

你可能感兴趣的:(Swift开关按钮(UISwitch)的用法)