如何在UIStackView中将垂直和水平居中 [英] How to center both vertical and horizontal inside a UIStackView

查看:302
本文介绍了如何在UIStackView中将垂直和水平居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 UIImageView ,尺寸为 50x50 .如果我有一个大小为100x100的UIView,并且想将图像居中放置,则只需将这些设置为

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

但是如何使用尺寸为100x100的 UIStackView 执行相同的操作?

But how do I do the same with a UIStackView of size 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 ?

推荐答案

使用两个堆栈视图.

具有中心对齐的垂直堆栈视图.

Vertical stack view with centre alignment.

内部是水平堆叠视图,中心对齐t.

Inside that is a horizontal stack view with centre alignment t.

里面就是你的形象.

这篇关于如何在UIStackView中将垂直和水平居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆