简体   繁体   中英

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 在此输入图像描述

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 ?

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.

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

在此输入图像描述

Check attribute inspector for stackview settings:

图片

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM