mask

Masks this view using the alpha channel of the given view.

View ModifieriOS 15.0+macOS 12.0+tvOS 15.0+watchOS 8.0+mask(alignment:_:) in SwiftUI

Declaration

React
compose().mask({
  alignment?: SwiftUI.Alignment,
  mask: ReactNode,
})
Swift
nonisolated func mask<Mask>(
    alignment: Alignment = .center,
    @ContentBuilder _ mask: () -> Mask
) -> some View
where Mask : View

Parameters

  • options.alignmentSwiftUI.Alignment

    The alignment for mask in relation to this view.

  • options.mask*ReactNode

    The view whose alpha the rendering system applies to the specified view.

Discussion

Use mask(_:) when you want to apply the alpha (opacity) value of another view to the current view.

This example shows an image masked by rectangle with a 10% opacity:

Image(systemName: "envelope.badge.fill")
    .foregroundColor(Color.blue)
    .font(.system(size: 128, weight: .regular))
    .mask {
        Rectangle().opacity(0.1)
    }

See also

More in Visual effects.