[ad_1]
This submit goes into nice element of SwiftUI’s new Grid view in iOS 16, nonetheless it makes use of static examples. I’ve created a demo undertaking beneath to indicate an instance, in my use case I have no idea the precise quantity or size of the strings in knowledge. Is it attainable to make use of this new Grid API to format these views in a manner that can evenly distribute them, i.e. assemble my code in order that, e.g. if 3 view’s don’t match, it can solely make 2 columns and push the third view to the following row in order that they will not overlap?
import SwiftUI
struct ContentView: View {
var knowledge = [
"Beatles",
"Pearl Jam",
"REM",
"Guns n Roses",
"Red Hot Chili Peppers",
"No Doubt",
"Nirvana",
"Tom Petty and the Heart Breakers",
"The Eagles"
]
var physique: some View {
Grid() {
GridRow {
ForEach(knowledge, id: .self) { bandName in
Textual content(bandName)
.fixedSize(horizontal: true, vertical: false)
}
}
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
[ad_2]

