The best way to use checkbox - IOS swift

前端 未结 5 528
谎友^
谎友^ 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 16:46

    Please try this.

    btn.setImage(UIImage(named: "uncheckImage"), for: UIControlState.normal)
    btn.setImage(UIImage(named: "checkImage"), for: UIControlState.selected)
    
    @IBAction func btn_box(sender: UIButton) {
    
         if btn.isSelected == true {
    
              btn.isSelected = false
         }
         else {
    
              btn.isSelected = true
         }
    }
    

提交回复
热议问题