DKLA
DKLA

Reputation: 243

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...

Upvotes: 14

Views: 4409

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90721

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.

Upvotes: 26

Related Questions