Instance Method インスタンスメソッド

background(ignoresSafeAreaEdges:)

Sets the view’s background to the default background style.

Declaration 宣言

func background(ignoresSafeAreaEdges edges: Edge.Set = .all) -> some View

Return Value 戻り値

A view with the background shape style drawn behind it.

Parameters パラメータ

edges

The set of edges for which to ignore safe area insets when adding the background. The default value is all. Specify an empty set to respect safe area insets on all edges.

Discussion 議論

This modifier behaves like background(_:ignoresSafeAreaEdges:), except that it always uses the background shape style. For example, you can add a background to a Label:


ZStack {
    Color.teal
    Label("Flag", systemImage: "flag.fill")
        .padding()
        .background()
}

Without the background modifier, the teal color behind the label shows through the label. With the modifier, the label’s text and icon appear backed by a region filled with a color that’s appropriate for light or dark appearance:

A screenshot of a flag icon and the word flag inside a rectangle; the

If you want to specify a View or a stack of views as the background, use background(alignment:content:) instead. To specify a Shape or InsettableShape, use background(_:in:fillStyle:) or background(_:in:fillStyle:), respectively.

See Also 参照

Background Elements