Layers a secondary view in front of the view.
SDKs
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
Framework
- Swift
UI
Declaration
Parameters
overlay
The view to layer in front of the view.
alignment
The alignment for
overlay
in relation to the view.
Return Value
A view that layers overlay
in front of the view.
Discussion
When you apply an overlay to a view, the original view continues to provide the layout characteristics for the resulting view. For example, the layout for the caption in this view fits within the width of the image:
Image("artichokes")
.overlay(
HStack {
Text("Artichokes") // Text to use as a caption.
Spacer()
}
.padding()
.foregroundColor(.white)
.background(Color.black.opacity(0.5)),
alignment: .bottom
)