How to center both vertical and horizontal inside a UIStackView

五迷三道 提交于 2019-12-06 03:20:51

问题


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

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 ?


回答1:


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.




回答2:


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




回答3:


Check attribute inspector for stackview settings:




回答4:


follow these steps.

1) drag Uiimageview.

2) click on UIimageview. Press Ctrl and drag downward or sidewise to parent view.

3) click on "centre vertically in view" and centre "horizontally in view"

4) then set height and width like below.

Thats it. your imageview will be at centre regardless of the device type. good luck.

leave a comment if you any question. Accept the answer if it helps you.



来源:https://stackoverflow.com/questions/45406910/how-to-center-both-vertical-and-horizontal-inside-a-uistackview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!