I have a LazyVStack which will grow vertically depending on how many elements are in it. However when it is generated, the elements go left to right, then down to the next row etc. I want it to order the elements vertically and then when it has reached the bottom of the column, move to the next and start doing the same again. Is this possible?
Here is the code I have so far
struct Player: Identifiable{
var id = UUID()
var name: String
}
var players = [Player(name: "Unknown"),
Player(name: "Player 1"),
Player(name: "Player 2"),
Player(name: "Player 3")]... this carries on for 23 players
let columns = [
GridItem(.flexible(), spacing: 0),
GridItem(.flexible(), spacing: 0)
]
VStack(spacing: 10){
LazyVGrid(columns: columns, spacing: 10){
ForEach(players){player in
Text(player.name)
.padding(.trailing)
}
}
}
.padding(.leading)
I'm thinking I may need a LazyHGrid instead, but the number of players passed in could change so I want it to be responsive. Any ideas?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…