Home > OS >  Selecting the name of a UIButton swift5
Selecting the name of a UIButton swift5

Time:03-16

I have a UIButton called picPressed, this UIButton has a background image. I want to to be able to get the name of the buttons background image. I am trying something like:

let hello = picPressed.backgroundImage.name()
Print(hello)

But get an error saying:

value of type '(UIControl.State) -> UIImage?' has no member 'name'

How can isolate this attribute in swift5?

CodePudding user response:

No, buttons don't remember their names (or the name of the image you install into them.)

I suggest you create an object that manages a button, takes a filename for an image, and remembers that filename for later. (Alternately you could subclass UIButton, but that can get complex.)

  • Related