View ModifieriOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+
Overloads
2 ways to call compose().containerBackground(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().containerBackground(
style: SwiftUI.ShapeStyle,
options: {
for: SwiftUI.ContainerBackgroundPlacement;
}
)nonisolated func containerBackground<S>(
_ style: S,
for container: ContainerBackgroundPlacement
) -> some View
where S : ShapeStyleParameters
style*SwiftUI.ShapeStyleoptions.for*SwiftUI.ContainerBackgroundPlacement
Discussion
The following example uses a LinearGradient as a background:
struct ContentView: View {
var body: some View {
NavigationStack {
List {
NavigationLink("Blue") {
Text("Blue")
.containerBackground(.blue.gradient, for: .navigation)
}
NavigationLink("Red") {
Text("Red")
.containerBackground(.red.gradient, for: .navigation)
}
}
}
}
}The .containerBackground(_:for:) modifier differs from the
View.background(_:ignoresSafeAreaEdges:) modifier by automatically
filling an entire parent container. ContainerBackgroundPlacement
describes the available containers.
- Parameters
- style: The shape style to use as the container background.
- container: The container that will use the background.
See also
More in Appearance.
- backgroundSets the view's background to a style.
- badgeGenerates a badge for the view from a localized string resource.
- badgeProminenceSpecifies the prominence of badges created by this view.
- borderAdds a border to this view with the specified style and width.
- buttonSizingThe preferred sizing behavior of buttons in the view hierarchy.
- headerProminenceSets the header prominence for this view.
- hiddenHides this view unconditionally.
- imageScaleScales images within the view according to one of the relative sizes available including small, medium, and large images sizes.
- labelIconToTitleSpacingSet the spacing between the icon and title in labels.
- labelReservedIconWidthSet the width reserved for icons in labels.
- labelsHiddenHides the labels of any controls contained within this view.
- labelsVisibilityControls the visibility of labels of any controls contained within this view.