Dar*_*isa 4 uikit ios swift swiftui
当您使用 SwiftUI 时,Form它会在前缘创建填充,这对Form输入很好,但我想向表单添加其他内容,例如占据整个屏幕宽度的图像,但因为图像在Form, 填充被应用,图像被稍微推离屏幕。如何删除所有Form填充?
struct MyForm: View {
var body: some View {
Form {
Image(uiImage: someImage)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: UIScreen.main.bounds.width)
TextField("Name", text: $name)
// Other fields
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道底层视图Form是UITableView我可以做的事情,比如UITableView.appearance().backgroundColor = .clear改变Form外观,但我不知道如何删除前导填充。
我也知道我可以将Image视图移到外面Form并将所有内容放在堆栈中,但这会产生我想避免的其他滚动问题。
这是一个解决方案。使用 Xcode 11.4 / iOS 13.4 测试
Image(uiImage: someImage)
.resizable()
.aspectRatio(contentMode: .fill)
.listRowInsets(EdgeInsets()) // << this one !!
Run Code Online (Sandbox Code Playgroud)
注意:UIScreen.main.bounds.width不需要硬编码
| 归档时间: |
|
| 查看次数: |
1536 次 |
| 最近记录: |