Reputation: 3909
My issue is that I can't find a way to set 3 UIButtons equal distances apart from each other and the 2 outer buttons that same equal distance from the left and right sides.
This is basically a drop-down view that will hold 3 buttons, and the constraints for x positioning all need to be related to each other somehow.
What concept in Autolayout am I missing?
Upvotes: 2
Views: 411
Reputation: 7549
Autolayout doesn't support this right out of the box.
Luckily there is a clever way how to do this. Insert transparent UIView
s between the buttons. Mark these UIView
's widths equal to each other. Now they will take equal spaces between each other.
Upvotes: 1
Reputation: 113
check this for sharing the parent space with ratio to child. check here
Upvotes: 0
Reputation: 12592
This will make all the 3 equally spaced with equal width and equal height
Upvotes: 1
Reputation: 5148
set center button2
Add leftcontent view and rightconent view fit bettwen button2 and left, right spaces
You can set constraints like following:
Upvotes: 1
Reputation: 3777
You can set them to equal distance. Here is an example:
Make sure to set Placeholder on the right for all the buttons, so it does not force the size on runtime.
Set each button to equal width with each other (select all and set equal width). Then, then set the width to placeholder, then set the left and right constraints on the left and right buttons. Then set the horizontal constraint on the center button. Then set the bottom constraint for the center, and constrain the right and left vertical to the center button vertical.
This should not matter with button width. Make sure your constraints between buttons are set.
At run:
Example with smaller button widths:
Upvotes: 0