LazyVGrid 中单元格的间距在所有方面都不相同
Spacing for cells in LazyVGrid are not the same on all sides
我有一个 LazyVGrid,我正在尝试使网格中所有单元格的间距相等。但是,单元格不断接触屏幕的边缘,我正在努力使其等于每个单元格的其余间距。它是这样的:
这是我的代码:
import SwiftUI
struct HomeView: View {
var body: some View {
NavigationView {
ScrollView {
LazyVGrid(columns: [GridItem](repeating: GridItem(.flexible()), count: 2)) {
ForEach(0..<6) { selection in
SelectionView()
}
}
}
.navigationTitle("The Deep End")
.navigationBarTitleDisplayMode(.inline)
}
}
}
struct SelectionView: View {
var body: some View {
ZStack {
}
.frame(maxWidth: .infinity, minHeight: 100)
.background(Color.green)
.cornerRadius(15)
}
}
这是一个演示代码,将所有可用间距选项指定为 20。
ScrollView {
// VV horizontal spacing VV vertical spacing
LazyVGrid(columns: [GridItem](repeating: GridItem(.flexible(), spacing: 20), count: 2), spacing: 20) {
ForEach(0..<6) { selection in
SelectionView()
}
}
.padding(20) // << surrounding spacing
我有一个 LazyVGrid,我正在尝试使网格中所有单元格的间距相等。但是,单元格不断接触屏幕的边缘,我正在努力使其等于每个单元格的其余间距。它是这样的:
这是我的代码:
import SwiftUI
struct HomeView: View {
var body: some View {
NavigationView {
ScrollView {
LazyVGrid(columns: [GridItem](repeating: GridItem(.flexible()), count: 2)) {
ForEach(0..<6) { selection in
SelectionView()
}
}
}
.navigationTitle("The Deep End")
.navigationBarTitleDisplayMode(.inline)
}
}
}
struct SelectionView: View {
var body: some View {
ZStack {
}
.frame(maxWidth: .infinity, minHeight: 100)
.background(Color.green)
.cornerRadius(15)
}
}
这是一个演示代码,将所有可用间距选项指定为 20。
ScrollView {
// VV horizontal spacing VV vertical spacing
LazyVGrid(columns: [GridItem](repeating: GridItem(.flexible(), spacing: 20), count: 2), spacing: 20) {
ForEach(0..<6) { selection in
SelectionView()
}
}
.padding(20) // << surrounding spacing