How to change background color of SwiftUI View? (Background Color)
Hi everyone! I just started learning SwiftUI and can't figure out how to change the background. In UIKit I was used to just doing `view.backgroundColor = .red`, but in SwiftUI it seems to be different.
I tried writing this:
```swift
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.background(Color.red)
}
}
```
The background changes, but only for the text itself, not the entire screen. How can I make the background fill the entire View area, including the Safe Area?
I also tried applying `.background()` to the entire `NavigationView`:
```swift
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Text("Title")
Text("Content")
}
}
.background(Color
```
No answers yet.
Log in to leave an answer
Blogs
Integration Testing Java with Docker: Advanced Techniques
.h or .hpp for C++ header files? Settling it once and for all
Design Patterns in Kotlin: Advanced Techniques with Examples
File Extension in PHP: 5 Ways in 2025 (Stack Overflow Question)