Using IB I've assigned images to a button's .normal, .highlighted, and .selected states. When pressing the button during a .normal->.selected transition (someButton.isSelected = true) the .highlighted image is correctly presented while touched, however when setting someButton.isSelected = false to return to .normal I see the standard quick-fade transition instead of my .highlighted image. I saw in this SO post from 2013 a similar problem, however I'm wondering if the solution is still applicable in Swift 4 as I'm not quite understanding it. My goal is to have the "glowing" image presented at each button touch. Thanks!
Here's the full code:
@IBAction func someButtonArray(_ sender: UIButton) {
UIView.transition(with: sender, duration: 0.3, options: .transitionCrossDissolve, animations: {
sender.setImage(UIImage(named: "TRANSITION_Pad-10.png"), for: UIControl.State.highlighted)
}, completion: nil)
if sender.isSelected == true {
UIView.transition(with: sender, duration: 0.3, options: .transitionCrossDissolve, animations: {
sender.setImage(UIImage(named: "INITIAL_Pad-13.png"), for: UIControl.State.normal)
}, completion: nil)
sender.isSelected = false
} else if sender.isSelected != true {
sender.isSelected = true
for buttons in 0...11 where buttons != (sender.tag) {
someButtonArray[buttons].isSelected = false
}
}
tableView.reloadData()
}
