Skip to content

Instantly share code, notes, and snippets.

@marybnq
Last active August 17, 2022 06:55
Show Gist options
  • Save marybnq/410fb553aec826f15bf8c8005e915f88 to your computer and use it in GitHub Desktop.
Save marybnq/410fb553aec826f15bf8c8005e915f88 to your computer and use it in GitHub Desktop.
A one-row scrollable LazyHGrid in SwiftUI
//Images' names
var names: [String] = ["heart.fill",
"star.fill",
"circle.hexagongrid.fill",
"leaf.fill",
"sun.max.fill",
"ladybug.fill",
"moon.fill",
"sparkles",
"snowflake"
]
var body: some View {
NavigationView{
VStack{
ScrollView(.horizontal){
LazyHGrid(rows: [GridItem(.flexible())], spacing: 10) {
ForEach(names[0..<names.count], id: \.self) {name in
ZStack{
LinearGradient(colors: [.pink.opacity(0.5),.purple.opacity(0.7)], startPoint: .top, endPoint: .bottom)
.frame(width: 90, height: 90, alignment: .center)
.clipShape(RoundedRectangle(cornerRadius: 25))
Image(systemName: name)
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 60, height: 60, alignment: .center)
}
}
} .fixedSize()
.padding()
}
Spacer()
}.navigationTitle("Scrollable Grid")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment