The best way to use checkbox - IOS swift

前端 未结 5 529
谎友^
谎友^ 2021-02-03 16:03

I am going to work on a project that will use a lot of checkboxes. I found a solution like below, but I know this not right way.

 @IBAction func btn_box(sender:          


        
5条回答
  •  野的像风
    2021-02-03 17:01

    There are lots of Checkbox control or you do it by this simple way:

    For Storyboard:

    1. Set your button's selected image:

    2. Set your button's default image:

    For Programmatically:

    btn_box.setBackgroundImage(UIImage(named: "box"), for: .normal)
    btn_box.setBackgroundImage(UIImage(named: "checkBox"), for: .selected)
    

    And in button action:

    @IBAction func btn_box(sender: UIButton) { 
        sender.isSelected = !sender.isSelected
    }
    

提交回复
热议问题