代码:如果有的话favCell > Text(item.title ?? "") in 2 lines
,那么为什么该行中显示不均匀的视图行?如何使该行 1 行文本高度或顶部和底部之间的空间也等于 2 行文本,请指导
我应该在哪里进行更改才能使一切平等,请指导
@ViewBuilder func favView() -> some View {
VStack {
LazyVGrid(columns: [
GridItem(.flexible(), spacing: 20),
GridItem(.flexible(), spacing: 20),
GridItem(.flexible(), spacing: 20),
GridItem(.flexible(), spacing: 20)
], spacing: 20) {
ForEach(0..<favMenu.count + 1, id: \.self) { ind in
if (ind == favMenu.count) {
addMoreButton()
} else {
favoriteButton(for: ind)
}
}
}
.padding(.top, 16)
}
.padding(.top, 35)
.padding(.horizontal, 24)
}
@ViewBuilder func favoriteButton(for index: Int) -> some View {
Button {
handleFavoriteSelection(at: index)
} label: {
favCell(item: favMenu[index], index: index)
}
.buttonStyle(.plain)
}
@ViewBuilder func favCell(item: AllMenu, index: Int) -> some View {
VStack(spacing: 10) {
VStack(spacing: 0) {
ZStack {
RoundedRectangle(cornerRadius: 15)
.fill(Color.Neumorphic.main)
.softOuterShadow()
.frame(width: 65, height: 65)
URLImageView(url: item.icon ?? "", width: 25, height: 25, renderingMode: .template, tintColor: .appGreen)
.frame(width: 25, height: 25)
}
.frame(width: 65, height: 65)
}
Text(item.title ?? "")
.font(.calibriRegular(with: 13))
.foregroundColor(.black)
.lineLimit(2)
.multilineTextAlignment(.center)
.frame(width: 70)
.fixedSize(horizontal: true, vertical: false)
.padding(.horizontal, 4)
.padding(.bottom, 10)
}
}
您可能想要
.alignment
为每个添加GridItem
:输出: