1

Trying to dynamically change a button image.

reloadStopButton.currentImage = UIImage(named: "logo0.png")

Throws...
Cannot assign to the result of this expression

Grr.. Where did i go wrong?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
kmiklas
  • 13,085
  • 22
  • 67
  • 103
  • Easy on the downvote people; now my account is locked. It's tough now, especially as Swift has just been released. – kmiklas Jun 16 '14 at 16:06

1 Answers1

1

You must use the button image setter:

reloadStopButton.setImage(UIImage(named: "logo0.png"), forState: UIControlState.Normal)

Button's need to know which state you are setting something for. This matters for things like their title, titleColor, and backgroundImage too.

If you look at the docs for currentImage you will see it is a readonly property. It just returns which image is currently being displayed. This can be useful for if you have different images showing for different states.

Firo
  • 15,448
  • 3
  • 54
  • 74