SwiftUI - 在列表/表单中显示图像,单元格周围没有边框

Fog*_*ter 2 image swiftui

我正在尝试在 SwiftUI 中创建一个ListorForm来显示一些字段。其中之一是图像。我希望它在单元格中显示没有任何边框,但行的内容似乎在单元格内包含某种我无法摆脱的固有边距。

这是我目前的代码......

List {
  Section("Photo") {
    Button {
      // do a thing
    } label: {
      Image(uiImage: image)
        .resizable()
        .aspectRatio(1, contentMode: .fit)
    }
  }
  .listRowBackground(Color.gray)
  TextField("Name", text: viewStore.binding(\.$name))
  DatePicker("DOB", selection: viewStore.binding(\.$dob), displayedComponents: [.date])
}
Run Code Online (Sandbox Code Playgroud)

这就是它的样子......

在此输入图像描述

这里确实有两个问题。

  1. 如何消除灰色边框以使图像填充到单元格的范围?
  2. 如何使用 UIKit 中的内容调整图像大小scaleAspectFill?目前它正在挤压图像以适应。

Fog*_*ter 5

好吧...我在输入问题时有了一些想法。

我通过在该部分提供 解决了这个问题(至少部分解决了)listRowInsets

Section {
  // the content
}
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Run Code Online (Sandbox Code Playgroud)

然后显示如下...

在此输入图像描述

现在致力于修复纵横比。

我使用这个答案修复了宽高比......

如何在 SwiftUI 中居中裁剪图像