It's been a few months since I started Swift. Referring to the SWIFT website I wrote the code as follows.
let layout2: [GridItem] = Array(repeating: .init(.flexible(minimum: 40, maximum: 75)), count: 5)
let layout = [GridItem(.fixed(75)),GridItem(.fixed(75)),GridItem(.fixed(75)),GridItem(.fixed(75)),GridItem(.fixed(75))]
let layout3: [GridItem] = [GridItem(.adaptive(minimum: 70), spacing: 5)]
struct ContentView: View {
@State var scores: [Int] = [1,3,4,3,2, 2,3,3,4,3]
var body: some View {
// Text("\(scores.count)") = 10
// ScrollView {
HStack {
LazyVGrid(columns: layout, spacing: 1) {
ForEach(scores, id: \.self) { num in
ZStack {
Rectangle()
.foregroundColor(.accentColor)
.frame(height: 45)
Text("\(num)")
.foregroundColor(.red)
} // ZStack
} // ForeEach
} // LazyVGrid
} // HStack
// } // ScrollView
} // body
} // ContentView
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}language
code-block
The result was different from what I thought and was as follows.
The content is an image of the output of 2 holes of data on the golf score card, and the score of 4 people was output to the screen. As a result, the first line is missing in the middle. The second hole is not all displayed. I would appreciate it if someone could let me know if there is a mistake in the code.