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:
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.