user16908243
user16908243

Reputation:

How to get a line in LazyVGrid with Foreach in swiftUI

How I could have a line on top of every columns in this lazyVGrid?

LazyVGrid(columns: Array(repeating: GridItem(spacing: .zero), count: 7), spacing: .zero) {
     ForEach(0..<36) { i in
        Text("\(i)")
     }
}

enter image description here

Upvotes: 2

Views: 1611

Answers (1)

swiftPunk
swiftPunk

Reputation: 1

Here is a way for you:

struct ContentView: View {
    
    private let range: ClosedRange<Int> = 0...35
    
    var body: some View {
        
        LazyVGrid(columns: Array(repeating: GridItem(spacing: .zero), count: 7), spacing: .zero) {
            ForEach(range, id: \.self) { index in
                
                VStack(spacing: .zero) {
                    
                    Text(String(describing: index))
                    
                    if (index < range.upperBound) { Color.primary.frame(height: 2.0) }
                    
                }
                
            }
        }
        .padding()
        
    }
    
}

enter image description here

enter image description here

Upvotes: 3

Related Questions