Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created July 17, 2020 19:00
Show Gist options
  • Save anupamchugh/8591adfb1bb300df0c62ed132ac7ca0e to your computer and use it in GitHub Desktop.
Save anupamchugh/8591adfb1bb300df0c62ed132ac7ca0e to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
var myData = Array(1...10).map{"\($0)"}
var column = Array(repeating: GridItem(.flexible(), spacing: 10), count: 3)
var body: some View {
VStack{
ScrollView {
LazyVGrid(columns: column, spacing: 10){
Section(header: Text("Header Without Pin").background(Color.yellow)){
ForEach(self.myData, id: \.self){ data in
Text(data).padding()
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 50)
.background(Color.red)
}
}
}
}
ScrollView {
LazyVGrid(columns: column, spacing: 10, pinnedViews: [.sectionHeaders]){
Section(header: Text("Header With Pin").background(Color.yellow)
.frame(minWidth:0, maxWidth: .infinity)){
ForEach(self.myData, id: \.self){ data in
Text(data).padding()
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 50)
.background(Color.green)
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment