UISwitch

创建Switch

let mySwitch = UISwitch(frame: CGRectMake(100,100,0,0))
mySwitch.tag = 101
self.view.addSubview(mySwitch)

开关与事件

mySwitch.on = false
mySwitch.addTarget(self, action: Selector("switchDidChange"), forControlEvents: UIControlEvents.ValueChanged)
func switchDidChange(){
    let swit = self.view.viewWithTag(101) as! UISwitch
    print(swit.on)
}

  

来源: http://www.cnblogs.com/spaceID/p/4976904.html

原文地址:https://www.cnblogs.com/spaceID/p/4976904.html