Search code examples
swiftuibuttonfocustvos

UIButton changes image back to original on focus (tvOS)


I have a button that acts as a switch: I check the current state of the variable (stored in used defaults) and attribute it in viewDidAppear

When I press the left button (ignore the right one) it is acts as it should - swapping out 2 UIImages on button's UIImageView

enter image description here

but as soon as button goes out of focus - button switches image back to the default one. if no default image is specified in IB - button just goes to blank image.

How can I ensure button keeps the image after is goes out of focus? Do I need to implement additional focus delegate methods or something? I'm new tvOS and some things just don't make sense to me yet.


Solution

  • Doh, it appears you cannot just swap out UIImage on UIImageView property and have to use a button setter for such matter:

    button.setImage(UIImage, forState: UIControlState.Normal)

    It works fine this way