Instance Method

blendMode(_:)

Sets the blend mode for compositing this view with overlapping views.

Declaration

func blendMode(_ blendMode: BlendMode) -> some View

Parameters

blendMode

The BlendMode for compositing this view.

Return Value

A view that applies blendMode to this view.

Discussion

Use blendMode(_:) to combine overlapping views and use a different visual effect to produce the result. The BlendMode enumeration defines many possible effects.

In the example below, the two overlapping rectangles have a .colorBurn effect applied, which effectively removes the non-overlapping portion of the second image:

HStack {
    Color.yellow.frame(width: 50, height: 50, alignment: .center)

    Color.red.frame(width: 50, height: 50, alignment: .center)
        .rotationEffect(.degrees(45))
        .padding(-20)
        .blendMode(.colorBurn)
}
Two overlapping rectangles showing the effect of the blend mode view modifier applying the colorBurn effect.

See Also

Compositing Views

enum BlendMode

Modes for compositing a view with overlapping content.

func compositingGroup() -> View

Wraps this view in a compositing group.

func drawingGroup(opaque: Bool, colorMode: ColorRenderingMode) -> View

Composites this view’s contents into an offscreen image before final display.

enum ColorRenderingMode

The working color space for color-compositing operations.