Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center both vertical and horizontal inside a UIStackView

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 ?

like image 516
Just a coder Avatar asked Jul 31 '17 03:07

Just a coder


2 Answers

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.

like image 159
Fogmeister Avatar answered Sep 24 '22 00:09

Fogmeister


You need to set the alignment to center inside attribute inspector of UIStackView

enter image description here

like image 38
Hussain Shabbir Avatar answered Sep 23 '22 00:09

Hussain Shabbir