EllipticalGradient

A radial gradient that draws an ellipse.

StructureiOS 15.0+macOS 12.0+tvOS 15.0+watchOS 8.0+EllipticalGradient in SwiftUI

Declaration

React
type EllipticalGradient =
  | { colors: Color[]; center?: UnitPoint; startRadiusFraction?: number; endRadiusFraction?: number; }
  | { gradient: Gradient; center?: UnitPoint; startRadiusFraction?: number; endRadiusFraction?: number; }
  | { stops: GradientStop[]; center?: UnitPoint; startRadiusFraction?: number; endRadiusFraction?: number; };
Swift
@frozen nonisolated struct EllipticalGradient

Overview

The gradient maps its coordinate space to the unit space square in which its center and radii are defined, then stretches that square to fill its bounding rect, possibly also stretching the circular gradient to have elliptical contours.

For example, an elliptical gradient centered on the view, filling its bounds:

EllipticalGradient(gradient: .init(colors: [.red, .yellow]))

When using an elliptical gradient as a shape style, you can also use ShapeStyle.ellipticalGradient(_:center:startRadiusFraction:endRadiusFraction:).

From Apple’s SwiftUI documentation. Code samples there are Swift.

See also

More in Drawing and shapes.