Contents

hueRotation(_:)

Applies a hue rotation effect to this view.

Declaration

nonisolated func hueRotation(_ angle: Angle) -> some View

Parameters

  • angle:

    The hue rotation angle to apply to the colors in this view.

Return Value

A view that applies a hue rotation effect to this view.

Discussion

Use hue rotation effect to shift all of the colors in a view according to the angle you specify.

The example below shows a series of squares filled with a linear gradient. Each square shows the effect of a 36˚ hueRotation (a total of 180˚ across the 5 squares) on the gradient:

struct HueRotation: View {
    var body: some View {
        HStack {
            ForEach(0..<6) {
                Rectangle()
                    .fill(.linearGradient(
                        colors: [.blue, .red, .green],
                        startPoint: .top, endPoint: .bottom))
                    .hueRotation((.degrees(Double($0 * 36))))
                    .frame(width: 60, height: 60, alignment: .center)
            }
        }
    }
}

[Image]

See Also

Transforming colors