So I've noticed when using padding() it creates an outside space/edge outside a view frame. Is there a way to eliminate that outside edge?
Here is .padding(.top, 0)

Here is .padding(.top, 1) the extra outside edge has appeared

Here is .padding(.top, 10) the outside edge remains on any padding above 1px from what I see.

import SwiftUI
struct TestView: View {
var body: some View {
VStack {
Text("")
.frame(width: 300, height: 20)
.background(Color(.black))
.cornerRadius(10)
Text("")
.frame(width: 300, height: 20)
.background(Color(.black))
.cornerRadius(10)
.padding(.top, 0)//here you can change the 0 to 1
}
}
}

The reason this happens is because the VStack automatically has its own spacing. Replace:
VStack {
/* ... */
}
with:
VStack(spacing: 0) {
/* ... */
}
This removes padding between each view within the VStack. I am assuming SwiftUI makes an assumption that if you want 0 padding, you want them touching, otherwise you likely want padding from within its own space within the VStack.
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