S.J
S.J

Reputation: 3071

Need assistance setting two buttons of equal width, side by side Autolayout

Using auto layout I am trying to create two buttons on the bottom like this

enter image description here

After dragging two buttons I set constraints like this

enter image description here

On Back button I set Leading Space to Container Margin and Bottom Space to Bottom Layout Guide

On Go To Settings button I set Trailing Space to Container Margin and Bottom Space to Bottom Layout Guide

Then I ctrl+Drag from Back button to Go To Settings button and set the Equal Widths constraint and I get this.

enter image description here

Then I update the Back button width same as Go To Settings button which is 101 and all constraints turn to blue.

But I want both buttons to cover half of the screen no matter what the size of screen is, same as shown in first screen shot, How to accomplish this?

Upvotes: 7

Views: 3077

Answers (4)

Bhavin Bhadani
Bhavin Bhadani

Reputation: 22374

you can done it using equal width to 2nd button like this

enter image description here

and the output is

enter image description here

Here is apple guide

Upvotes: 25

Jatin Patel - JP
Jatin Patel - JP

Reputation: 3733

You can followed the layout changes. you will get what you want.

Layout for Back button. enter image description here Layout for Go to Setting button.

enter image description here

Upvotes: 0

Vladimir K
Vladimir K

Reputation: 1382

You need to add one more constraint - set horizontal space between buttons to 0

enter image description here

Upvotes: 1

Levi
Levi

Reputation: 7343

You can have the equal widths constraint between the buttons, but you also have to tell them which is that width you need.

So drag from a button to the superview, add an equal widths constraint. Then in the properties of the constraint you've added, set the multiplier to 0.5, this way your buttons should be on half the screen.

Upvotes: 2

Related Questions