How to center both vertical and horizontal inside

2020-07-11 09:46发布

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 ?

4条回答
成全新的幸福
2楼-- · 2020-07-11 10:24

Check attribute inspector for stackview settings:

image

查看更多
我命由我不由天
3楼-- · 2020-07-11 10:29

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

enter image description here

查看更多
爷的心禁止访问
4楼-- · 2020-07-11 10:35

follow these steps.

1) drag Uiimageview.

enter image description here

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

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

4) then set height and width like below. enter image description here

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.

查看更多
够拽才男人
5楼-- · 2020-07-11 10:44

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.

查看更多
登录 后发表回答