创建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) }