class ViewController: UIViewController,UITextFieldDelegate {
var switchView:UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
switchView = UISwitch()
switchView.center = CGPoint(x: 100.0, y: 60.0)
switchView.isOn = false
switchView.addTarget(self, action: #selector(switchAction(s:)), for: .valueChanged)
self.view.addSubview(switchView)
}
@objc func switchAction(s:UISwitch) -> Void {
if s.isOn {
NSLog("开")
} else {
NSLog("关")
}
}
}
网友评论