When you use a SwiftUI Form
it creates padding on the leading edge, which is fine for Form
input but I would like to add additional content to the Form e.g. an image that takes the entire width of the screen, but because the image is in the Form
, padding gets applied and the image gets pushed off screen slightly. How can I remove all Form
padding?
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
}
}
}
I know that the underlying view for Form
is a UITableView
where I can do things like UITableView.appearance().backgroundColor = .clear
to change the Form
appearance, but I can't figure out how to remove the leading padding.
I also know I can move the Image
view outside the Form
and put everything in a stack, but that creates other issues with scrolling that I'd like to avoid.
Here is a solution. Tested with Xcode 11.4 / iOS 13.4
Image(uiImage: someImage)
.resizable()
.aspectRatio(contentMode: .fill)
.listRowInsets(EdgeInsets()) // << this one !!
Note: hardcode to UIScreen.main.bounds.width
is not needed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With