I am trying to create a list with cards or rows which grows downwards. It's added to a horizontal scroll view which can have multiple lists.
How to make the card fill the width - some padding of the screen?
The current code is
struct RowView: View {
var body: some View {
Rectangle()
.foregroundColor(.blue)
.frame(width: 80, height: 80, alignment: .center) // shows a square, but how to set size depending on screen?
//.frame(minWidth: 100, maxWidth: .infinity, minHeight: 100, maxHeight: .infinity, alignment: .topLeading) // nothing shows up
}
}
struct ListView: View {
var body: some View {
ScrollView(.vertical) {
VStack(spacing: 16) {
RowView()
RowView()
RowView()
}
.padding()
}
}
}
struct ContentView: View {
var body: some View {
ScrollView(.horizontal) {
HStack {
ListView()
ListView()
ListView()
}
}
}
}
I tried using GeometryReader
, but it's not working.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…