vasudha Jha
vasudha Jha

Reputation: 31

Adding a button to an image view present in a stack view

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.

Upvotes: 0

Views: 947

Answers (2)

Ajay saini
Ajay saini

Reputation: 2460

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

Upvotes: 0

Milan Nosáľ
Milan Nosáľ

Reputation: 19737

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

Upvotes: 2

Related Questions