[英]How to center both vertical and horizontal inside a UIStackView
I have a simple UIImageView with 50x50 size . 我有一个50x50大小的简单UIImageView 。 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 如果我有一个大小为100x100的UIView并且我想将图像置于其中心,我所要做的就是设置这些
But how do I do the same with a UIStackView of size 100x100 ? 但是我如何使用尺寸为100x100的UIStackView做同样的事情呢?
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 ? 问题是,如何在UIStackview内部垂直和水平居中显示图像?
Use two stack views. 使用两个堆栈视图。
Vertical stack view with centre alignment. 垂直堆栈视图与中心对齐。
Inside that is a horizontal stack view with centre alignment t. 内部是具有中心对齐t的水平堆栈视图。
Inside that is your image. 里面就是你的形象。
Check attribute inspector for stackview settings: 检查属性检查器的stackview设置:
follow these steps. 跟着这些步骤。
1) drag Uiimageview. 1)拖动Uiimageview。
2) click on UIimageview. 2)单击UIimageview。 Press Ctrl and drag downward or sidewise to parent view. 按Ctrl键并向下或向侧面拖动到父视图。
3) click on "centre vertically in view" and centre "horizontally in view" 3)点击“在视图中垂直居中”并居中“水平在视野中”
4) then set height and width like below. 4)然后设置高度和宽度,如下所示。
Thats it. 而已。 your imageview will be at centre regardless of the device type. 无论设备类型如何,您的imageview都将位于中心位置。 good luck. 祝好运。
leave a comment if you any question. 如果您有任何疑问,请发表评论。 Accept the answer if it helps you. 如果有帮助,请接受答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.