简体   繁体   English

使用自动布局将UIButton和UILabel居中

[英]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的新手,我试图通过UICollectionViewUICollectionView底部之间的空间中的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.

相关问题 自动布局:标题视图逐渐包含 UILabel + UIButton - Autolayout: Title View that Grows to Encompass UILabel + UIButton 使用自动布局将UILabel + UIImageView在Superview中水平居中 - Horizontally center UILabel + UIImageView in superview using autolayout 使用Autolayout在UIView内部水平居中UILabel + UIImageView - Horizontally Center UILabel + UIImageView inside UIView with Autolayout 如何布局UILabel和UIButton并将它们居中? - How to layout a UILabel and a UIButton and center them? 自定义UIButton中的UILabel,已使用AutoLayout将其调整为按钮的大小 - UILabel in a custom UIButton that adjusted to the button's size with AutoLayout UILabel使用自动布局实现居中位置和右侧按钮的自动高度 - UILabel implemente autoheight with center placement and a button to the right using AutoLayout iOS Autolayout:将UILabel的左边缘与容器中的水平中心对齐? - iOS Autolayout: Align left edge of a UILabel with horizontal center in container? 如何在UITableViewCell中获取UIImageView大小(任何对象,如UIButton,UILabel)。 我用了自动排版 - How to get UIImageView Size (any Object Like UIButton, UILabel) in UITableViewCell. I used Autolayout AutoLayout UILabel多行 - AutoLayout UILabel multiline 具有自动布局的UILabel高度动画 - UILabel height animation with autolayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM