bearacuda13 bearacuda13 - 1 year ago 105
Swift Question

Find the Name of a Background Image of a Button in Swift

I have named a set of images like this:





In order to change the background image of a button, my code is written to take the string of the background image's name, and either append or take off the "~" to change it to the correct image.

So I tried this:

let backgroundString = String(selector.currentBackgroundImage!)

But I get this:

<UIImage: 0x146d98b80>, {485, 300}

Is there any way to get the plain name of the background image?

Any help is greatly appreciated.

Answer Source

i had a similar problem. Fortunately I know the state of the button when the viewcontroller is displayed, so I created a String control, which was something like this:

var buttonState = "not selected" 

then when the user clicks on the button I check:

if (buttonState == "not selected") {

   // change buttonState to "selected"

   // change the image of the button

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download