UISwitch

作者: CaptainRoy | 来源:发表于2019-08-04 16:32 被阅读0次
    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("关")
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:UISwitch

          本文链接:https://www.haomeiwen.com/subject/znsydctx.html