Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How to arrange 3 UIButtons side-by-side.I am using Auto-layout. My requirement is:

1.they should be equal width regardless of device

2.occupy vertically from starting to end of the view

enter image description here

i tried different ways, i failed to achieve that. Is it possible through interface builder

like image 682
UdayM Avatar asked Mar 23 '16 06:03

UdayM


2 Answers

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

enter image description here


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.

enter image description here

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

Step 3: Add Constraints to StackView. like below. enter image description here

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

enter image description here

And its Done!

like image 74
Jatin Chauhan Avatar answered Oct 25 '22 02:10

Jatin Chauhan


Select 3 buttons and give this constraints

  - leading
  - trailing
  - bottom
  - Height
  - equal width 

You can check some references from equal width to 3 labels and from setting two buttons of equal width, side by side

like image 20
EI Captain v2.0 Avatar answered Oct 25 '22 02:10

EI Captain v2.0