I'm doing the switch from UIKit to SwiftUI and I'm trying to achieve the following "Collection View".
Assuming I have an array of pairs (i.e: [[<Image0>, <Image1>], <Image2>, <Image3>]]..), my plan was to:
- Create
ScrollView - Create
HStackand embed it inside theScrollView - For each group, create
VStackwith some kind of filling proportional behavior
My current code:
struct AutoScrollingImages: View {
let imageGroups: [[String]]
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(0..<imageGroups.count, id: \.self) { groupIndex in
VStack(spacing: .zero) {
ForEach(imageGroups[groupIndex], id: \.self) { imageName in
Image(imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.cornerRadius(8.0)
}
}
.background(.gray)
}
}
}.background(Color.red)
}
}
But it fails horribly. I'd love help on this one.
