I want to show a separator line in my SwiftUI app. To achieve that, I tried to create an empty view with a fixed frame and a background color / border:
EmptyView() .frame(width: 200, height: 2) .background(Color.black) // or: .border(Color.black, width: 2)
Unfortunately, I cannot see any dark view showing up.
Is there a way to show a separator / line view?
If the canvas isn't visible, select Editor > Editor and Canvas to show it. The Horizontal Divider is displayed as a horizontal line to divide views. Inside a HStack the divider is displayed as a vertical line. The size of the divider can be changed with the frame modifier.
For a vertical divider, you set the width to the thickness you want. Text("A visual element that can be used to separate other content.") Set a vertical divider thickness by setting the width.
Unfortunately, there is no official way to remove line separators in SwiftUI. That said, we can make use of the UIKit API to tweak the line separator of the List view in SwiftUI.
Use Divider:
A visual element that can be used to separate other content.
Example:
struct ContentView : View { var body: some View { VStack { Text("Hello World") Divider() Text("Hello Another World") } } }
Output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With