Pyae Phyoe Shein
Pyae Phyoe Shein

Reputation: 13837

How to make same width for 5 button horizontally in xcode

I've designed those 5 button in my storyboard based on iPhone6. Now problem is my client told me to make their app can be workable in iPhone5 onwards. Current those 5 buttons in iPhone5 cannot be displayed proportionally as same width. That's why my question is please let me know how to make same width for 5 button horizontally in xcode?

Upvotes: 3

Views: 1458

Answers (3)

Bioche
Bioche

Reputation: 468

Using a stackView works great but for those whose target is below iOS 9, you can do it very simply with autolayout. Just select all 5 labels and use the "pin" icon on the bottom of the storyboard to check "equal width".

Upvotes: 2

Luca Angeletti
Luca Angeletti

Reputation: 59536

As already said in the comments you can create an Horizontal Stack View. Then add the 5 buttons to the Stack View.

enter image description here

Finally you can select the spacing by selecting the Stack View and, in the Attribute Inspector, increasing the Spacing field.

Upvotes: 0

Adrian
Adrian

Reputation: 16735

Try this:

  1. Add 5 UIButtons to yourViewController.
  2. Highlight buttons
  3. Click "Stack" icon at the bottom of the storyboard window.
  4. On the UIStackView's attribute inspector, make sure it's "horizontal", distribution is set to "Fill Equally", and adjust the spacing to whatever you want.
  5. Pin the UIStackView to left/right, top/bottom.

It should look something like this when you're done:

enter image description here

Upvotes: 2

Related Questions