swiftui

How to change thickness of Divider in 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 the Divider()?

Edit: Sorry for not making it clear. I meant thickness, not width.


Solution

  • 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)
        }
    }