Sets the contrast and separation between similar colors in this view.
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
The intensity of color contrast to apply. negative values invert colors in addition to applying contrast.
A view that applies color contrast to this view.
Apply contrast to a view to increase or decrease the separation between similar colors in the view.
In the example below, the
contrast(_:) modifier is applied to a set of red squares each containing a contrasting green inner circle. At each step in the loop, the
contrast(_:) modifier changes the contrast of the circle/square view in 20% increments. This ranges from -20% contrast (yielding inverted colors — turning the red square to pale-green and the green circle to mauve), to neutral-gray at 0%, to 100% contrast (bright-red square / bright-green circle). Applying negative contrast values, as shown in the -20% square, will apply contrast in addition to inverting colors.