小编Mar*_*lQT的帖子

如果没有足够的空间 swiftui,如何将网格项发送到下一行

我对 swift 有点陌生,正在努力解决这个看似简单的问题。我希望网格中包含三列,除非网格项的内容不适合列的设置宽度。具体来说,我有过滤器按钮,其中一些按钮的名称很长。我想将“早餐”的 TagView 发送到下一行并移动每个标签视图,以便它们全部适合并且文本不必换行。但不知道如何做到这一点。

我尝试调整网格项中的最小值和最大值,并调整列中的 GridItem 数量。然而,不幸的是,这并没有奏效。任何建议将不胜感激。

这是我的代码:

    var filterBar: some View {
        VStack {
            filterBarTitle
            if filtersOpened {
                let columns = [GridItem(.adaptive(minimum: 85), spacing:0)]
                
                LazyVGrid(columns: columns) {
                    ForEach(allRecipeTags) { recipeTag in
                        TagView(tag: recipeTag, selected: selectedTags.contains(recipeTag), canToggle: true, onTap: {
                            if selectedTags.contains(recipeTag) {
                                print("removing \(recipeTag)")
                                selectedTags.removeAll(where: { $0 == recipeTag })
                            } else {
                                print("adding \(recipeTag)")
                                selectedTags.append(recipeTag)
                            }
                        })
                        .border(.red)
                    }
                }
                .border(.blue)
            }
        }
        .padding([.top, .bottom])
        .border(width: 1, edges: [.bottom], color: Color("24292F").opacity(0.3))
        .padding(.horizontal)
        .padding([.bottom], filtersOpened ? 8 : …
Run Code Online (Sandbox Code Playgroud)

swift swiftui

1
推荐指数
1
解决办法
678
查看次数

标签 统计

swift ×1

swiftui ×1