The best way to use checkbox - IOS swift

前端 未结 5 589
谎友^
谎友^ 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:45

    You can use the approach below which will most helpful: In your StoryBoard or ViewDidLoad assign the image for UIButton:

    checkBoxButton.setBackgroundImage(UIImage(named: "box"), forState: UIControlState.Normal)
    checkBoxButton.setBackgroundImage(UIImage(named: "checkBox"), forState: UIControlState.Selected)
    

    After this in your @IBAction Method just implement the following code:

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

    This will do the trick.

提交回复
热议问题