我一直在try 创建一个列表并扩展行之间的空间,同时保持它们的全宽,但我似乎遇到了一些挑战.我认为方法是让列表中的HStack从一端水平扩展到另一端,并try 缩小顶部和底部.我以为帧修改器可以做到这一点,但它似乎不起作用.

enter image description here enter image description here

代码如下:

    NavigationView() {
        List(caseList) {caseItem in
            HStack {
                
                
                Image(systemName: "folder.fill.badge.person.crop")
                    .foregroundColor(.accentColor)

                VStack(alignment: .leading, spacing: 5) {
                    
                    Text(caseItem.alias)
                    Text("# team members")
                        .font(.subheadline)
                        .foregroundColor(.secondary)
                }
                
            }
            .listRowInsets(EdgeInsets())
            .background(Color.green)
            .clipShape(RoundedRectangle(cornerRadius: 10))
            .badge(Int.random(in: 0..<5))
            .listRowSeparatorTint(Color.cyan, edges: .all)
            .listRowSeparator(.visible)
            .listRowBackground(Color.orange)
            .frame(
                maxWidth: .infinity,
                minHeight: 0,
                maxHeight: .infinity,
                alignment: .topLeading
            )
            
        }
        .listStyle(InsetGroupedListStyle())
    }
    .onAppear() {
        loadCases()
    }
    .navigationTitle("Cases")
    

我还想删除列表项目和顶部 case 之间的差距.

UPDATE

我添加了第二张图片,以红色显示我希望绿色形状覆盖的内容.我想我的目标是让它们看起来更像独立的项目,有更多的信息和更大的间距.这不应该是一个详尽的 list ,在大多数情况下,人们只会有一个,所以我正在努力使其成为实质性的 list .我在玩扩展/折叠的,所以如果你只有一个,它会被扩展,看起来不会那么孤独.

推荐答案

如果我正确理解了目标,那么就在这里(使用Xcode 13.4/iOS 15.5测试)

demo

            HStack {
                Image(systemName: "folder.fill.badge.person.crop")
                    .foregroundColor(.accentColor)

                VStack(alignment: .leading, spacing: 5) {

                    Text(caseItem.alias)
                    Text("# team members")
                        .font(.subheadline)
                        .foregroundColor(.secondary)
                }
                Spacer()
            }
            .badge(Int.random(in: 0..<5)).padding(.horizontal)
            .listRowInsets(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0))
            .background(Color.green)
            .listRowSeparatorTint(Color.cyan, edges: .all)
            .listRowSeparator(.visible)
            .listRowBackground(Color.orange)

Swift相关问答推荐

WWDC Swift并发会话中的厨房服务示例令人困惑

字符串目录不适用于SWIFT包

在visionOS RealityView中使用.GenerateText时,未显示Reality Composer Promaterial 纹理

如何将图像插入到矩形中

在不传递参数的情况下使用Init方法?

如何获取嵌套数组中项的路径以修改数组?

协议元类型'SomeProtocol.Type'上无法使用静态成员'currency'

使用View()和List()无法显示影子

如何从我的 macOS 应用程序打开 (.log) 文件?

ConfirmationDialog取消swiftui中的错误

从文字创建数组时的 Swift 宏

Swift-SceneKit-无法从art.scnassets加载.scn文件

Swift - 订阅视图之外的绑定值

将内容与工作表顶部而不是中间对齐

自定义选取器的出现导致其他视图重新排列

UITableViewCell 不显示 detailTextLabel.text - Swift

Swift:创建 UIImage 数组

swift 3 如何获取明天和昨天的日期(注意特殊情况)新月或新年

'类 'className' 的 NSManagedObject 必须具有有效的 NSEntityDescription.错误

将 UIImage 剪成圆形