Layers a view behind the current view, useful for adding colors, gradients, images, or custom views as backgrounds.
97.2% of iOS users can use this modifier
iOS 13+ required
.background(_:) Sets a view or shape as the background
content: View or ShapeStyle.background(_:ignoresSafeAreaEdges:) Sets background that can extend into safe area
content: View or ShapeStyleedges: Edge.SetAdd a solid color background
Text("Hello, World!")
.padding()
.background(.blue)Use a linear gradient as background
Text("Hello, World!")
.padding()
.background(
LinearGradient(
colors: [.blue, .purple],
startPoint: .top,
endPoint: .bottom
)
)Layer a rounded rectangle behind content
Text("Hello, World!")
.padding()
.background(
RoundedRectangle(cornerRadius: 10)
.fill(.blue.opacity(0.2))
)Loading related modifiers...
The .background() modifier requires iOS 13 or later. This means 97.2% of current iOS users can use this modifier.
Apply the .background() modifier to any SwiftUI view. Check the code examples above for usage patterns.
Visit the official Apple documentation for detailed information.