How to add Equal Spacing and equal width for button in iOS Auto layout

Yuvaraj.M picture Yuvaraj.M · Sep 30, 2015 · Viewed 25.8k times · Source

Am new to Auto layout constraints in Xcode. I have one Bottom View like UITabBar with 6 UIButtons. Without constraints I aligned those buttons with 5 space padding with each buttons and each buttons has 50 width. Now,I am trying to make it by using Auto layout to support all Screen sizes.

In Storyboard constrains I set equal width for 6 buttons and I made 60 space between each buttons. I set first button 0 to leading space and I set the last button 0 to tail constraints.

I want the buttons with equal width and flexible spaces between views in all device sizes.

Can anyone pleas help me? Looking for the help. Thanks in advance.

enter image description here

Answer

EI Captain v2.0 picture EI Captain v2.0 · Sep 30, 2015

check this image and made your constraints like below...

enter image description here

RESULT:- preview in different sizes

enter image description here


With Stackview (For iOS 9.0 and above)

enter image description here

NOTE: If you have to make app for iOS 9 and later then UIStackView is another option for you