简体   繁体   English

如何为堆栈视图设置约束?

[英]How to set constraints to stack views?

I'm trying to achieve this layout using the interface builder我正在尝试使用界面构建器来实现这种布局在此处输入图片说明

I've already tried to embedded the bottom button inside another stackview, also tried to set it out of the stack view but nothing works as expected what have now is this我已经尝试将底部按钮嵌入另一个堆栈视图中,也尝试将其设置在堆栈视图之外,但没有按预期工作,现在是这样在此处输入图片说明 And getting this result并得到这个结果在此处输入图片说明

Can someone tell me what constraints are missing or what is wrong with my current constraints?有人可以告诉我缺少哪些约束或我当前的约束有什么问题吗?

You usually don't need to add too many constraints to the stack view's arranged subviews.您通常不需要向堆栈视图的排列子视图添加太多约束。 Setting the distribution and alignment correctly is the key.正确设置分布和对齐是关键。 The constraints involving Stop Button are either unnecessary or causing the conflict that you see in the console.涉及停止按钮的约束要么是不必要的,要么会导致您在控制台中看到的冲突。

To position the stack view, you just need to pin its top, bottom, leading, trailing edges to the safe area.要定位堆栈视图,您只需要将其顶部、底部、前缘、后缘固定到安全区域。 For example:例如:

在此处输入图片说明

Then, set the alignment of all the stack views to "Fill", and the distribution of all the stack views to "Fill Equally".然后,将所有堆栈视图的对齐方式设置为“填充”,并将所有堆栈视图的分布设置为“等量填充”。

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

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