Skip to main content

Command Palette

Search for a command to run...

SwiftUI Vertical Divider

Updated

Using the standard Divider view and setting its width to 1 will create a vertical divider: Divider().frame(width: 1)

Example in action:

struct VerticalDividerExample: View {
    var body: some View {
        HStack(spacing: 20) {
           Text("Left")
           Divider().frame(width: 1)
           Text("Right")
        }
        .padding()
        .frame(width: 200, height: 75)
    }
}

Setting its width to anything greater than 1 will also produce the vertical effect but it will not render greater than one pixel wide and instead just add padding on each side.

We use vertical dividers in the stats view in our time tracking app, Tim.