简体   繁体   English

iOS自动布局:将一个按钮的边缘与另一个按钮的中心对齐?

[英]iOS Auto Layout: Align the edge of one button to the center of another button?

So I have two UIButtons that I'd like to align, but not specifically the edges. 所以我有两个UIButtons,我想对齐,但不是特别是边缘。 I would like to align the (left) edge of one button to the (horizontal) center of another button. 我想将一个按钮的(左)边缘与另一个按钮的(水平)中心对齐。 So I want it to look like this: 所以我希望它看起来像这样:

Button1的

How would I do this AutoLayout in Interface Builder and/or programatically? 我如何在Interface Builder中和/或以编程方式执行此AutoLayout? I hope this isn't too much of a beginner question, but iOS AutoLayout can be so confusing at times... 我希望这不是一个初学者问题,但iOS AutoLayout有时会让人感到困惑......

In IB, create any horizontal constraint between the two buttons. 在IB中,在两个按钮之间创建任何水平约束。 For example, align their centers. 例如,调整他们的中心。 Then, select the new constraint object and the Size inspector. 然后,选择新约束对象和“大小”检查器。 There, you can change which attributes are aligned. 在那里,您可以更改对齐的属性。 Select the leading edge of the top button. 选择顶部按钮的前缘。 Now the CenterX of the bottom button is aligned to the leading edge of the top button. 现在,底部按钮的CenterX与顶部按钮的前缘对齐。

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

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