b_pcakes
b_pcakes

Reputation: 2540

How to evenly space buttons horizontally in xcode

How can I evenly space a row of 4 or more buttons horizontally in Xcode? I'm totally new to xcode and I've played around a lot with constraints, but with no success. I would appreciate a step by step explanation if possible, thanks!

Upvotes: 3

Views: 4182

Answers (2)

Mohshin Shah
Mohshin Shah

Reputation: 298

1) Create a container view and apply Leading - Top - Trailing to the superview

2) add a button A and apply leading - top - bottom

3) take button B horizontal space to A - Centre Vertically - Equal width and height

4) take button C horizontal space to B - Centre Vertically - Equal width and height

5) take button D horizontal space to A - Centre Vertically - Equal width and height and TRAILING TO THE SUPER VIEW.

Update Frames.

enter image description here

Upvotes: 1

Annabelle Sykes
Annabelle Sykes

Reputation: 263

Make a horizontal spacing constraint between each button. Then, change the constraint constant to what you prefer. To add the horizontal spacing constraint, control-drag from one button to the other, and select it from the pop-up menu.

Upvotes: 0

Related Questions