M13Checkbox在Swift中选择了动作?

时间:2019-04-26 11:28:37

标签: swift checkbox

我正在使用M13Checkbox吊舱。我想在选中复选框时将“记住我”打印到labeltextfield,而在未选中复选框时将“记住我”打印。当我单击它时,它只是说:“不记得我了。”

  let checkboxm13: M13Checkbox = {

        let checkboxe = M13Checkbox()
        checkboxe.stateChangeAnimation = .stroke
        checkboxe.addTarget(self, action: #selector(checkboxvalue(sender:)), for: .valueChanged)
        return checkboxe

    }()
 @objc func checkboxvalue(sender: Checkbox) {
        if sender.isSelected == true {
            labelcheckbox.text = ("Beni Hatırla")

        }
        if sender.isSelected == false {
            labelcheckbox.text = ("Hatırlama")           
        }       
    }

1 个答案:

答案 0 :(得分:0)

使用checkState而不是isSelected

@objc func checkboxvalue(_ sender: M13checkbox) {
    switch sender.checkState {
        case .checked:
            labelcheckbox.text = "Beni Hatırla"
        break

        case .unchecked:
            labelcheckbox.text = "Hatırlama"    
        break

        case .mixed:
            //empty...
        break       
    }       
}