简体   繁体   中英

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. 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? I hope this isn't too much of a beginner question, but iOS AutoLayout can be so confusing at times...

In IB, create any horizontal constraint between the two buttons. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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