lundi 18 mars 2019

Save with UserDefaults that checkbox is check or uncheck swift

I've designed a recall checkbox. But when I log out of the application, I want the checkbox value to be set to UserDefaults as true or false. So I want the checkbox to remember true or false when I get into the application.

 lazy var circleBox: Checkbox = {

        let squareBox = Checkbox(frame: CGRect(x: 22, y: 290, width: 25, height: 25))
        squareBox.tintColor = .black
        squareBox.borderStyle = .square
        squareBox.checkmarkStyle = .square
        squareBox.uncheckedBorderColor = .lightGray
        squareBox.borderWidth = 1

        squareBox.addTarget(self, action: #selector(checkboxvalue(sender:)), for: .valueChanged)
        return squareBox

    }()

 @objc func checkboxvalue(sender: Checkbox) {
        if sender.isChecked == true {
            labelcheckbox.text = ("Remember me")
            action((Any).self)


        }else{
            labelcheckbox.text = ("Don't remember")

        }

    }




Aucun commentaire:

Enregistrer un commentaire