0

I am trying to add a button to an image view which lies in a stack view. But whenever I try to add the button after adding the image view, the stack view gets divided into two parts, one housing the button and the other housing the image view.

I want to add an icon which is an image view, on top which there's a button which one clicked does the needful.

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

2

Just add the button to the stackView and use background on that button to set the icon:

button.setBackgroundImage(UIImage(named: "icon"), for: .normal)

Or through storyboards select a button and set it in attributes inspector:

Settings background image for button using storyboards

Milan Nosáľ
  • 19,169
  • 4
  • 55
  • 90
0

Instead of using a button, first add a uiview in place of button and then add image and button inside the uiview.

Ajay saini
  • 2,352
  • 1
  • 11
  • 25