hueRotation

Applies a hue rotation effect to this view.

View ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+hueRotation(_:) in SwiftUI

Declaration

React
compose().hueRotation(angle: SwiftUI.Angle)
Swift
nonisolated func hueRotation(_ angle: Angle) -> some View

Parameters

  • 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)
            }
        }
    }
}

See also

More in Visual effects.