Skip to content

SwiftUI: Divider

Traditionally, you will create a UIView to create a Divider and set it’s height or width to 0 depending on the direction that you would like it to be. Phew, that was a lot of hassle including configuring the constraint and everything else.

SwiftUI really is game changing and you are able to create a Divider so easy that you would never think twice to swift back to UIKit.

A visual element that can be used to separate other content.

Apple Documentation

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

  • How to build a Divider from scratch.

Prerequisites

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

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

Divider

To use a divider, simply call Divider().

To make the divider Horizontal, you can use HStack.

You can even tweak the height if it’s horizontal and the width if it’s vertical. In addition to that, changing color is part of the package as well.

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.