Instance Method

opacity(_:)

Sets the transparency of this view.

Declaration

func opacity(_ opacity: Double) -> some View

Parameters

opacity

A value between 0 (fully transparent) and 1 (fully opaque).

Return Value

A view that sets the transparency of this view.

Discussion

Apply opacity to reveal views that are behind another view or to de-emphasize a view. The following shows two versions of the same image side by side; at left is the original, and at right is a duplicate with its opacity set to 0.5:

When applying the opacity(_:) modifier to a view that already has an opacity, the modifier supplements—rather than replaces—the view’s opacity.

See Also

Applying Graphical Effects to a View

func brightness(Double) -> View

Brightens this view by the specified amount.

func contrast(Double) -> View

Sets the contrast and separation between similar colors in this view.

func colorInvert() -> View

Inverts the colors in this view.

func colorMultiply(Color) -> View

Adds a color multiplication effect to this view.

func blendMode(BlendMode) -> View

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

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.

func saturation(Double) -> View

Adjusts the color saturation of this view.

func grayscale(Double) -> View

Adds a grayscale effect to this view.

func hueRotation(Angle) -> View

Applies a hue rotation effect to this view.

func luminanceToAlpha() -> View

Adds a luminance to alpha effect to this view.