[英]Center UIButton and UILabel with Autolayout
I'm a newbie when it comes to UIConstraints
and i'm trying to center the "Continue Button" and "No, thanks" with Auto Layout
in the space between the UICollectionView
and the bottom in the xib
. 我是关于UIConstraints
的新手,我试图通过UICollectionView
和UICollectionView
底部之间的空间中的Auto Layout
将“继续按钮”和“不,谢谢” xib
。 Which UIConstraints
should i add? 我应该添加哪些UIConstraints
?
Here is the implementation i made 这是我所做的实现
As you can see in the image, i implemented 3 Stack Views with the different components. 如您在图像中看到的,我用不同的组件实现了3个Stack View。 To make them all "one" i put them in a Stack with constraints <= to the bottom and top and constraints with a fixed size so that they don't go pass the bounds of the view. 为了使它们全都成为“一个”,我将它们放在堆栈中,其中约束<=到底部和顶部,约束具有固定的大小,这样它们就不会越过视图的边界。
If you don't want to use absolute values, you need two more transparent views to obtain the layout you want. 如果您不想使用绝对值,则需要另外两个透明视图来获取所需的布局。
One view, should be added above "Continue" and it should have it's top margin set to the collectionView
and the bottom margin set to "Continue". 一个视图,应该添加到“ Continue”上方,并且其上边距应设置为collectionView
,下边距应设置为“ Continue”。 The second view should be placed under "No thanks" and it should have the top margin set to "No thanks" and the bottom margin set to the bottom of the superView. 第二个视图应置于“不,谢谢”下,并且其上边距应设置为“不,谢谢”,而下边距应设置为superView的底部。 You can have both views take up all the horizontal space by adding left and right margins equal to the superView. 通过添加等于superView的左右边距,可以使两个视图都占据所有水平空间。
After you set the constraints I mentioned above, you have to add one more equal height constraint between the two extra views. 设置完我上面提到的约束后,必须在两个额外的视图之间添加一个相等的高度约束。 This will ensure that the space above "Continue" and under "No thanks" will always be equal. 这样可以确保“继续”上方和“不,谢谢”下方的空间始终相等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.