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.
To follow along this tutorial, you’ll need some basic knowledge in:
- A basic familiarity with Swift.
- At least Xcode 11
To use a divider, simply call
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.
Text("Top text that appear above the divider")
Text("Bottom text that appear below the divider")
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: