在水平 UIStackView 中底部对齐 UILabels 序列的文本 [英] Bottom-align the text of a sequence of UILabels within a horizontal UIStackView

查看:23
本文介绍了在水平 UIStackView 中底部对齐 UILabels 序列的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在水平 UIStackView 中以编程方式对齐 UILabels 序列的文本,以便所有文本都位于视图的底部?

How do I programmatically align the text of a sequence of UILabels within a horizontal UIStackView so that all text is at the bottom of the views?

下面是我所拥有的和我想要的图像.我已经知道如何创建视图,我只是不知道需要哪些属性或约束才能使文本在视图底部对齐.谢谢.

Below is an image of what I have and what I want. I already know how to create the views, I just can't figure out what properties or constraints are needed to get the text to align on the bottom of the views. Thanks.

推荐答案

与@mahbaleshwar 提到的相关,UILabels 总是居中对齐.然而,UIStackView 有一些属性可以帮助你实现你想要的视图,也许没有黄色背景.

Related to what @mahbaleshwar mentioned, UILabels always center align. However, UIStackView has some properties that will help you achieve the view you want, maybe without the yellow backgrounds.

stackView.alignment = bottom 会将所有内容对齐到底部.

stackView.alignment = bottom will align everything to the bottom.

但是,如果您需要黄色背景,则需要将标签放置在视图中.该视图将具有黄色背景,stackView.alignment = fill 将强制这些视图填充空间.然后,使用约束,您可以将标签固定到父视图的前缘、后缘和底缘.分配文本时,标签应调整大小,以提供所需的外观.

However, if you need the yellow background, you will need to place your labels in a view. The view will have the yellow background, stackView.alignment = fill will force those views to fill the space. Then, using constraints, you can pin your label to the leading, trailing and bottom edges of the parent view. The label should resize when you assign the text, giving the appearance you want.

这篇关于在水平 UIStackView 中底部对齐 UILabels 序列的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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