Need Assistance Setting Two Buttons of Equal Width, Side by Side Autolayout

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

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

Sample Image

and the output is

Sample Image

Here is apple guide

iOS Autolayout: two buttons of equal width, side by side

Add the following constraints

  1. Assign equal width from button1 to button2.
  2. Assign horizontal spacing between both buttons.
  3. Assign leading space from button1 to its superview.
  4. Assign trailing space from button2 to its superview.
  5. Assign top space to both the buttons.

    Let me know if it works for you.

Can't get auto layout to make two buttons side by side stay there

Insert those buttons into horizontal StackView component (which is available in iOS 9 and later) and set alignment to fill. Setup their constraints to have aspect ration on themselves and setup them to have equal width (at least that)... Much simpler approach IMO

see:

https://www.raywenderlich.com/114552/uistackview-tutorial-introducing-stack-views

How to add constraints to the following two buttons

Ctrl + Drag from one button to the other and add the Equal Width constraint.

Autolayout : Align two button side by side and move to right side when there is no image

Using two different buttons inside UIStackView will be very easy & effective:

2 Diffrent buttons inside UIStackview
1st button is hide

Add constraints to side by side buttons

Just give constraint as in my image

First give constraint to textfield then Select both button and give constraints like in image and be sure that both buttons width and height is same

Constraint

It should look like this

Image

Autolayout with equal width and setting priority

iOS9 only apps:

This might be a good time to use the new Horizontal Stack View. Just set distribution to fill equally and alignment to fill

For iOS8 support:

You'll have to set the width constraint to equal width between the components and the horizontal spacing to 0

Set button1 to equal width with button2 then button1 to equal width with button3. This should be enough.

Arrange 3 UIButtons(of equal width) side-by-side

There are 2 ways to do this.

Way 1:

With use of equal width constraint of button

Select all 3 buttons and add

top, left , right, height and equal width

Sample Image


Way 2:
With use of Stack view

Step 1: Add 3 buttons.

Step 2: Select all that buttons, Once you selected, click on the Stack button in the Auto Layout toolbar at the bottom right of the storyboard canvas. see below in image.

Sample Image

Alternatively you can embed in From Editor -> Embed in -> StackView

Step 3:
Add Constraints to StackView. like below.
Sample Image

Step 4:
Select StackView, Once selected go to Attributes inspector. Change the Distribution to Fill Equally:

Sample Image

And its Done!



Related Topics



Leave a reply



Submit