简体   繁体   English

UIStackView内嵌的UIStackView对齐方式

[英]UIStackView embedded within UIStackView alignment

I'm trying to use embedded UIStackViews to get something that looks like this: 我正在尝试使用嵌入式UIStackViews来获得如下所示的内容:

Label1 ---------<spacing>-------Label2
Label3 -<can take up this whole area>-

So I have label1 and label2 in one horizontal UIStackView. 所以我在一个水平的UIStackView中有label1和label2。 And then that innerStackView vertically stacked with Label3. 然后,将innerStackView与Label3垂直堆叠。 But I'd like to have Label1 left aligned all the way to the left, and then label2 all the way on the right. 但是我想让Label1一直向左对齐,然后再将label2一直向右对齐。 I can add spacing, but it seems like there should be a better way to do this. 我可以添加间距,但是似乎应该有更好的方法来做到这一点。

The reason why I'm trying to do it this way is because sometimes label2 and label3 are not populated and I read that UIStackViews can handle that layout really easily when one of those items are hidden and I wanted to try to learn something different than doing it with labels and AutoLayout. 我尝试这样做的原因是因为有时不填充label2和label3,并且我读到当其中一个项目被隐藏时,UIStackViews可以非常轻松地处理该布局,并且我想尝试学习与做不同的事情它带有标签和自动版式。

The stackview alignment and distribution properties affect all arranged subviews the same way, ie you cannot have one left and one right. stackview的对齐方式和分布属性以相同的方式影响所有排列的子视图,即,不能有一个左和一个右。 However, you can set the horizontal stackview to fill equally and set label1 text alignment to left and label2 text alignment to right and it will achieve the same effect. 但是,您可以将水平堆栈视图设置为均等填充,并将label1文本对齐方式设置为左侧,将label2文本对齐方式设置为右侧,这将实现相同的效果。

You have this: 你有这个:
label1 and label2 stacked inside one horizontal stackView that we'll name S1. label1和label2堆叠在一个水平的stackView中,我们将其命名为S1。 Then you stacked S1 together with label3 into a vertical stack that we'll referto by S2. 然后,将S1和label3一起堆叠到一个垂直堆叠中,我们将由S2对其进行引用。 OK?? 好??

My proposal: 我的建议:
Try to stack label1 into a vertical stackView (with alignment leading) S3, and label2 into another vertical stackView (with alignment trailing) S4. 尝试将label1堆叠到一个垂直的stackView(对齐方式在前)S3,并将label2堆叠到另一个垂直的stackView(对齐方式在尾部)S4。 and then stack these two stackviews S3 y S4 inside S1. 然后将这两个堆栈视图S3和S4堆叠在S1中。 I think this should work fine. 我认为这应该很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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