Skip to content

SwiftUI: HStack

Last updated on February 24, 2020

HStack stands for Horizontal Stack. HStack is able to take in every view that you add in and handle the height and width for you so you don’t have to worry much of the constraint.

A view that arranges its children in a horizontal line.

Apple Documentation

In this tutorial, you’ll learn what it takes to build a HStack in SwiftUI. You’ll learn:

  • How to build a HStack from scratch.

Prerequisites

To follow along this tutorial, you’ll need some basic knowledge in:

  • A basic familiarity with Swift.
  • At least Xcode 11

HStack

HStack definitely brings in a lot of improvement when it comes to designing the UI making it really easy and flexible to change from time to time. Always remember that HStack is just a view that contain other views which is called subviews.

There isn’t much spacing between the subviews. By adding spacing as a parameter of HStack, that would automatically generate some space between the subviews.

You can even tweak the alignment, currently it is by default center. You can try top and bottom just to see the differences. By adding a Rectangle, you will be able to clearly tell the differences.

Where to go From Here

If you feel like you are ready to take on more challenges, feel free to check out some other tutorials that we have created:

Published inSwiftUI

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © DaddyCoding 2020.