colorEffect

Returns a new view that applies shader to self as a filter effect on the color of each pixel.

View ModifieriOS 17.0+macOS 14.0+tvOS 17.0+colorEffect(_:isEnabled:) in SwiftUI

Declaration

React
compose().colorEffect(
  shader: SwiftUI.Shader,
  options?: {
    isEnabled?: boolean;
  }
)
Swift
nonisolated func colorEffect(
    _ shader: Shader,
    isEnabled: Bool = true
) -> some View

Parameters

  • The shader to apply to self as a color filter.

  • options.isEnabledboolean

    Whether the effect is enabled or not.

Return value

A new view that renders self with the shader applied as a color filter.

Discussion

For a shader function to act as a color filter it must have a function signature matching:

[[ stitchable ]] half4 name(float2 position, half4 color, args...)

where position is the user-space coordinates of the pixel applied to the shader and color its source color, as a pre-multiplied color in the destination color space. args... should be compatible with the uniform arguments bound to shader. The function should return the modified color value.

See also

More in Visual effects.