我正在尝试在 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)
这就是它的样子......
这里确实有两个问题。
scaleAspectFill?目前它正在挤压图像以适应。好吧...我在输入问题时有了一些想法。
我通过在该部分提供 解决了这个问题(至少部分解决了)listRowInsets。
Section {
// the content
}
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Run Code Online (Sandbox Code Playgroud)
然后显示如下...
现在致力于修复纵横比。
我使用这个答案修复了宽高比......