Computer >> Computer tutorials >  >> Programming >> IOS

Aligning two buttons vertically in iOS


Auto Layout is one the most important element when it comes to designing an iOS Application. UI development has become a lot more versatile and easier using Auto Layout.

For Aligning two buttons vertically we will be using Auto Layout.

So let’s get started!

Step 1: Open Xcode → New Projecr → Single View Application → Let’s name it “AlignButtons”

Step 2: Open Main.storyboard and add two buttons, name them button 1 and button 2.

Aligning two buttons vertically in iOS

Step 3: Select both the buttons and align them vertically using the Add New Alignment Constraint menu.

Aligning two buttons vertically in iOS

Step 4: Select both the buttons tap on Add new constraints and set it to equal widths.

Aligning two buttons vertically in iOS

Step 5: Now Select left button tap on Add new constraints again and set leading and trailing spaces to 20 points.

Aligning two buttons vertically in iOS

Step 6: Now Select Right button tap on Add new constraints again and set leading and trailing spaces to 20 points.

Aligning two buttons vertically in iOS

And that’s all as soon as you’ll click on Add 2 Constraints you’ll see you buttons aligned vertically.

Aligning two buttons vertically in iOS