One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

GraphicsContext.Shading

struct · iOS 15.0+ · SDK 27.1

struct Shading

A color or pattern that you can use to outline or fill a path. Use a shading instance to describe the color or pattern of a path that you outline with a method like ``stroke(_:with:style:)``, or of the interior of a region that you fill with the ``fill(_:with:style:)`` method. Get a shading instance by calling one of the `Shading` structure's factory methods. You can base shading on: - A ``Color``. - A ``Gradient``. - Any type that conforms to ``ShapeStyle``. - An ``Image``. - What you've already drawn into the context. - A collection of other shading instances.

Members (18)

get · iOS 15.0+

foreground

TypeScript
static get foreground(): GraphicsContext_Shading
Swift declaration
static var foreground: GraphicsContext.Shading { get }

A shading instance that fills with the foreground style from the graphics context's environment.

static · iOS 15.0+

tiledImage

TypeScript
static tiledImage(image: Image, origin?: { x: number; y: number }, sourceRect?: { x: number; y: number; width: number; height: number }, scale?: number): GraphicsContext_Shading
Swift declaration
static func tiledImage(_ image: Image, origin: CGPoint = .zero, sourceRect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1), scale: CGFloat = 1) -> GraphicsContext.Shading

Returns a shading instance that tiles an image across the infinite plane. - Parameters: - image: An ``Image`` to use as fill. - origin: The point in the current user space where SwiftUI places the bottom left corner of the part of the image defined by `sourceRect`. The image repeats as needed. - sourceRect: A unit space subregion of the image. The default is a unit rectangle, which selects the whole image. - scale: A factor that you can use to control the image size. - Returns: A shading instance filled with a tiled image.

static · iOS 18.0+

meshGradient

TypeScript
static meshGradient(mesh: MeshGradient): GraphicsContext_Shading
Swift declaration
static func meshGradient(_ mesh: MeshGradient) -> GraphicsContext.Shading

Returns a shading instance that fills with a mesh gradient. - Parameters: - mesh: The mesh gradient defining the filled colors. - Returns: A shading that fills using the mesh gradient.

static · iOS 18.0+

conicGradient

TypeScript
static conicGradientCenterAngleOptions(gradient: AnyGradient, center: { x: number; y: number }, angle?: Angle, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func conicGradient(_ gradient: AnyGradient, center: CGPoint, angle: Angle = Angle(), options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading instance that fills a conic (angular) gradient. - Parameters: - gradient: An ``AnyGradient`` instance that defines the colors of the gradient. - center: The point in the current user space on which SwiftUI centers the gradient. - angle: The angle about the center that SwiftUI uses to start and finish the gradient. The gradient sweeps all the way around the center. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a conic gradient.

static · iOS 15.0+

conicGradient

TypeScript
static conicGradientCenterAngleOptions36822(gradient: Gradient, center: { x: number; y: number }, angle?: Angle, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func conicGradient(_ gradient: Gradient, center: CGPoint, angle: Angle = Angle(), options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading instance that fills a conic (angular) gradient. - Parameters: - gradient: A ``Gradient`` instance that defines the colors of the gradient. - center: The point in the current user space on which SwiftUI centers the gradient. - angle: The angle about the center that SwiftUI uses to start and finish the gradient. The gradient sweeps all the way around the center. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a conic gradient.

static · iOS 18.0+

linearGradient

TypeScript
static linearGradientStartPointEndPointOptions(gradient: AnyGradient, startPoint: { x: number; y: number }, endPoint: { x: number; y: number }, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func linearGradient(_ gradient: AnyGradient, startPoint: CGPoint, endPoint: CGPoint, options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading instance that fills a linear (axial) gradient. The shading instance defines an axis from `startPoint` to `endPoint` in the current user space and maps colors from `gradient` to lines perpendicular to the axis. - Parameters: - gradient: An ``AnyGradient`` instance that defines the colors of the gradient. - startPoint: The start point of the gradient axis. - endPoint: The end point of the gradient axis. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a linear gradient.

static · iOS 15.0+

linearGradient

TypeScript
static linearGradientStartPointEndPointOptions95406(gradient: Gradient, startPoint: { x: number; y: number }, endPoint: { x: number; y: number }, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func linearGradient(_ gradient: Gradient, startPoint: CGPoint, endPoint: CGPoint, options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading instance that fills a linear (axial) gradient. The shading instance defines an axis from `startPoint` to `endPoint` in the current user space and maps colors from `gradient` to lines perpendicular to the axis. - Parameters: - gradient: A ``Gradient`` instance that defines the colors of the gradient. - startPoint: The start point of the gradient axis. - endPoint: The end point of the gradient axis. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a linear gradient.

static · iOS 18.2+

radialGradient

TypeScript
static radialGradientStartCenterStartRadiusEndCenterEndRadiusOptions(gradient: AnyGradient, startCenter: { x: number; y: number }, startRadius: number, endCenter: { x: number; y: number }, endRadius: number, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func radialGradient(_ gradient: AnyGradient, startCenter: CGPoint, startRadius: CGFloat, endCenter: CGPoint, endRadius: CGFloat, options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading that fills a two-point radial gradient. - Parameters: - gradient: An ``AnyGradient`` instance that defines the colors of the gradient. - startCenter: The strat point in the current user space on which SwiftUI centers the gradient. - startRadius: The distance from the center where the gradient starts. - endCenter: The end point in the current user space on which SwiftUI centers the gradient. - endRadius: The distance from the center where the gradient ends. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a radial gradient.

static · iOS 18.2+

radialGradient

TypeScript
static radialGradientStartCenterStartRadiusEndCenterEndRadiusOptions99395(gradient: Gradient, startCenter: { x: number; y: number }, startRadius: number, endCenter: { x: number; y: number }, endRadius: number, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func radialGradient(_ gradient: Gradient, startCenter: CGPoint, startRadius: CGFloat, endCenter: CGPoint, endRadius: CGFloat, options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading that fills a two-point radial gradient. - Parameters: - gradient: A ``Gradient`` instance that defines the colors of the gradient. - startCenter: The start point in the current user space on which SwiftUI centers the gradient. - startRadius: The distance from the center where the gradient starts. - endCenter: The end point in the current user space on which SwiftUI centers the gradient. - endRadius: The distance from the center where the gradient ends. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a radial gradient.

static · iOS 18.0+

radialGradient

TypeScript
static radialGradientCenterStartRadiusEndRadiusOptions(gradient: AnyGradient, center: { x: number; y: number }, startRadius: number, endRadius: number, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func radialGradient(_ gradient: AnyGradient, center: CGPoint, startRadius: CGFloat, endRadius: CGFloat, options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading instance that fills a radial gradient. - Parameters: - gradient: An ``AnyGradient`` instance that defines the colors of the gradient. - center: The point in the current user space on which SwiftUI centers the gradient. - startRadius: The distance from the center where the gradient starts. - endRadius:The distance from the center where the gradient ends. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a radial gradient.

static · iOS 15.0+

radialGradient

TypeScript
static radialGradientCenterStartRadiusEndRadiusOptions59147(gradient: Gradient, center: { x: number; y: number }, startRadius: number, endRadius: number, options?: GraphicsContext_GradientOptions): GraphicsContext_Shading
Swift declaration
static func radialGradient(_ gradient: Gradient, center: CGPoint, startRadius: CGFloat, endRadius: CGFloat, options: GraphicsContext.GradientOptions = GradientOptions()) -> GraphicsContext.Shading

Returns a shading instance that fills a radial gradient. - Parameters: - gradient: A ``Gradient`` instance that defines the colors of the gradient. - center: The point in the current user space on which SwiftUI centers the gradient. - startRadius: The distance from the center where the gradient starts. - endRadius:The distance from the center where the gradient ends. - options: Options that you use to configure the gradient. - Returns: A shading instance filled with a radial gradient.

static · iOS 15.0+

color

TypeScript
static colorRedGreenBlueOpacity(colorSpace: Color_RGBColorSpace, red: number, green: number, blue: number, opacity?: number): GraphicsContext_Shading
Swift declaration
static func color(_ colorSpace: Color.RGBColorSpace = .sRGB, red: Double, green: Double, blue: Double, opacity: Double = 1) -> GraphicsContext.Shading

Returns a shading instance that fills with a color in the given color space. - Parameters: - colorSpace: The RGB color space used to define the color. The default is ``Color/RGBColorSpace/sRGB``. - red: The red component of the color. - green: The green component of the color. - blue: The blue component of the color. - opacity: The opacity of the color. The default is `1`, which means fully opaque. - Returns: A shading instance filled with a color.

static · iOS 15.0+

color

TypeScript
static colorWhiteOpacity(colorSpace: Color_RGBColorSpace, white: number, opacity?: number): GraphicsContext_Shading
Swift declaration
static func color(_ colorSpace: Color.RGBColorSpace = .sRGB, white: Double, opacity: Double = 1) -> GraphicsContext.Shading

Returns a shading instance that fills with a monochrome color in the given color space. - Parameters: - colorSpace: The RGB color space used to define the color. The default is ``Color/RGBColorSpace/sRGB``. - white: The value to use for each of the red, green, and blue components of the color. - opacity: The opacity of the color. The default is `1`, which means fully opaque. - Returns: A shading instance filled with a color.

static · iOS 15.0+

color

TypeScript
static color(color: Color): GraphicsContext_Shading
Swift declaration
static func color(_ color: Color) -> GraphicsContext.Shading

Returns a shading instance that fills with a color. - Parameter color: A ``Color`` instance that defines the color of the shading. - Returns: A shading instance filled with a color.

static · iOS 15.0+

style

TypeScript
static style(style: SDKHandle): GraphicsContext_Shading
Swift declaration
static func style<S>(_ style: S) -> GraphicsContext.Shading where S : ShapeStyle

Returns a shading instance that fills with the given shape style. Styles with geometry defined in a unit coordinate space map that space to the rectangle associated with the drawn object. You can adjust that using the ``ShapeStyle/in(_:)`` method. The shape style might affect the blend mode and opacity of the drawn object. - Parameter style: A ``ShapeStyle`` instance to draw with. - Returns: A shading instance filled with a shape style.

static · iOS 17.0+

shader

TypeScript
static shader(shader: Shader, bounds?: { x: number; y: number; width: number; height: number }): GraphicsContext_Shading
Swift declaration
static func shader(_ shader: Shader, bounds: CGRect = .zero) -> GraphicsContext.Shading

Returns a shading instance that fills with the results of querying a shader for each pixel. For a shader function to act as a shape fill it must have a function signature matching: [[ stitchable ]] half4 name(float2 position, args...) where `position` is the user-space coordinates of the pixel applied to the shader, and `args...` should be compatible with the uniform arguments bound to `shader`. The function should return the premultiplied color value in the color space of the destination (typically sRGB). - Parameters: - shader: The shader defining the filled colors. - bounds: The rect used to define any `bounds` arguments of the shader. - Returns: A shading instance that fills using the shader.

static · iOS 15.0+

palette

TypeScript
static palette(array: Array<GraphicsContext_Shading>): GraphicsContext_Shading
Swift declaration
static func palette(_ array: [GraphicsContext.Shading]) -> GraphicsContext.Shading

Returns a multilevel shading instance constructed from an array of shading instances. - Parameter array: An array of shading instances. The array must contain at least one element. - Returns: A shading instance composed from the given instances.

get · iOS 15.0+

backdrop

TypeScript
static get backdrop(): GraphicsContext_Shading
Swift declaration
static var backdrop: GraphicsContext.Shading { get }

A shading instance that draws a copy of the current background.

Skipped declarations

No declarations were skipped in this snapshot.

All SwiftUICore types →