in button add image to button on click

Deviland

I have a button with a background Image and Text overlaid, when I click the button I want to remove the text from the button and replace with an image. I'm stuck how to get a reference to the button in the action to add the image.

Button(action: {
  print("3 clicked")
  self.background(Image("cross100x100"))
  self.disableButton = true
}) {
  Text("Button text")
}
.disabled(disableButton)

The above code doesn't work

Asperi

when I click the button I want to remove the text from the button and replace with an image

I'm not sure why disableButton is here, but for above the approach might be as follows

@State private var clicked = false

...

Button(action: {
  self.clicked = true
}) {
  if self.clicked {
     Image("cross100x100")
  } else {
     Text("Button text")
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related