Properties2
TypeIdea
Note createdFeb 17, 2025

When programming with SwiftUI, we could try to have some code like:

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .padding()
        .background(.red)  // <-- this!
    }
}

We could expect that code to show the boilerplate code and tint the whole screen red. That will not happen thought: it will only fill the boundaries of the current view, leaving a huge white space around.

There is a common impulse to think “how can I fill the space behind with that color?”. It is paramount to understand that you should not. There is nothing behind our views (except UIHostingController which you should definitely not touch).

Instead, you should modify your current view’s .frame(maxWidth: .infinity, maxHeight: .infinity) or use a ZStack if needed. As a SwiftUI developer, there is nothing else but your views.