Skip to content

Instantly share code, notes, and snippets.

@karm435
Created March 22, 2022 10:02
Show Gist options
  • Save karm435/8d1ee123ba5da72e86de0c9516c24d99 to your computer and use it in GitHub Desktop.
Save karm435/8d1ee123ba5da72e86de0c9516c24d99 to your computer and use it in GitHub Desktop.
LazyVGrid Sample
import SwiftUI
struct CustomText: View {
private let index: Int
init(index: Int) {
print("init CustomText \(index)")
self.index = index
}
var body: some View {
Text("This is custom text view \(index)")
}
}
struct ContentView: View {
var columns: [GridItem] = Array(repeating: .init(.fixed(20), spacing: 5, alignment: .center), count: 2)
var body: some View {
ScrollView(.vertical) {
LazyVGrid(columns: columns, alignment: .leading) {
ForEach(0...100, id:\.self) { index in
CustomText(index: index)
//Text("This is sample")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment