Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change width of Divider in SwiftUI?

Tags:

swiftui

On few screens of my SwiftUI app I am using Divider() between few elements. This Divider is rendered as a very thin grey (or black?) line. I am guessing 1 point. How can I change the width of Divider()?

like image 897
mallow Avatar asked Nov 10 '19 09:11

mallow


People also ask

How do you set the divider width in flutter?

How to Add Vertical Divider: VerticalDivider( color: Colors. black, //color of divider width: 10, //width space of divider thickness: 3, //thickness of divier line indent: 10, //Spacing at the top of divider. endIndent: 10, //Spacing at the bottom of divider. )

What is SwiftUI divider?

A divider in SwiftUI is an easy and concise way to help separate content within a view.

How do I draw a horizontal line in SwiftUI?

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.


1 Answers

You can create any divider you wish, colors, width, content... As in below example.

struct ExDivider: View {
    let color: Color = .gray
    let width: CGFloat = 2
    var body: some View {
        Rectangle()
            .fill(color)
            .frame(height: width)
            .edgesIgnoringSafeArea(.horizontal)
    }
}
like image 67
Asperi Avatar answered Oct 04 '22 19:10

Asperi