简体   繁体   English

自动布局约束和堆栈视图

[英]Auto Layout constraints and stack views

I have 12 buttons, and two stackViews, each 6 buttons are in a stack. 我有12个按钮和两个stackViews,每个6个按钮位于一个堆栈中。 not all the buttons are shown all the time. 并非所有按钮都始终显示。

I'm using in some situations, for example: 我在某些情况下使用例如:

buttonx.isHidden = true

what I want is that the Top constraint of each button to be always 8 points far from whats above it, knowing that whats above it can be something else in every situation (it can be the upper stack view border or another button's bottom). 我想要的是每个按钮的顶部约束始终与其上方的距离相距8个点,要知道在每种情况下其上方的位置可能是其他东西(它可以是上部堆栈视图边框或另一个按钮的底部)。

so doesn't matter which combination of buttons are showing (".ishidden = false") at that moment, to be always organised one under the other by "8" points. 因此,此时显示的按钮组合(“ .ishidden = false”)无关紧要,始终将其按“ 8”分在另一个按钮的下方进行组织。

the first button will be 8 from the stack top border and the 2nd will be 8 from the bottom of the button thats above it and etc... 第一个按钮从堆栈顶部边框开始为8,第二个按钮从上方的按钮底部开始为8,依此类推...

2- how can make the two stack view appear near each other if the screen is wide enough, and then if the screen is not enough the two stacks to be under one another. 2-如果屏幕足够宽,那么如何使两个堆栈视图彼此靠近,然后,如果屏幕不够大,两个堆栈就不能彼此叠置。

I'm still learning how to use the auto-layout and constraints, help would be very appreciated!! 我仍在学习如何使用自动布局和约束,将不胜感激!

EDIT: (photo for clarity) 编辑:(为清晰起见,照片)

[ [ 在此处输入图片说明]

So for example in one situation: only button y, d, k, are shown. 因此,例如在一种情况下:仅显示按钮y,d,k。 I want them to appear in the stack view under each other with an equal distance. 我希望它们以相等的距离出现在堆栈视图中。

First regarding the 8 pts between each button you need to set spacing property of the stackView ( Find it in attributes inspector) 首先要考虑每个按钮之间的8点,您需要设置stackView的间距属性(在属性检查器中找到它)

Second according to the sum of widths of the 2 stackViews you can either decide 其次,根据两个stackViews的宽度总和,您可以决定

1- make top equal for stack1&2 1-使top1和stack2相等

2- make top of stack2 equal to bottom of stack1 2-使stack2的顶部等于stack1的底部

which can be done programmatically to avoid static widths 可以通过编程来避免静态宽度

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

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