In Swift 4.2 and Xcode 10.1
Add image for selected UIButton
button.addTarget(self, action: #selector(self.onclickDateCheckMark), for: .touchUpInside)//Target
button.setImage(UIImage.init(named: "uncheck"), for: UIControl.State.normal)//When selected
button.setImage(UIImage.init(named: "check"), for: UIControl.State.highlighted)//When highlighted
button.setImage(UIImage.init(named: "check"), for: UIControl.State.selected)//When selected
But if you want to change selected button image you need to change it's selected state. Then only selected image will appear in your button.
@objc func onclickDateCheckMark(sender:UIButton) {
if sender.isSelected == true {
sender.isSelected = false
print("not Selected")
}else {
sender.isSelected = true
print("Selected")
}
}