How to center both vertical and horizontal inside a UIStackView

Just a coder picture Just a coder · Jul 31, 2017 · Viewed 15.6k times · Source

I have a simple UIImageView with 50x50 size. If I had a UIView of size 100x100 and I wanted to center the image inside of it, all I have to do is set these enter image description here

But how do I do the same with a UIStackView of size 100x100?

EDIT i think i should have been more clear. The questions is, how do i center the image both vertically & horizontally inside of the UIStackview ?

Answer

Fogmeister picture Fogmeister · Jul 31, 2017

Use two stack views.

Vertical stack view with centre alignment.

Inside that is a horizontal stack view with centre alignment t.

Inside that is your image.