跳转至
Structure

LinearGradient

A linear gradient.

Declaration

@frozen struct LinearGradient : ShapeStyle, View

Overview

struct ExampleView: View {
    var body: some View {
        RoundedRectangle(cornerRadius: 10)
            .fill(LinearGradient(
                    gradient: Gradient(colors: [.green, .blue, .purple]),
                    startPoint: .leading,
                    endPoint: .trailing))
            .padding()
    }
}
A view containing a rounded rectangle with a 10 point corner, padding, and a linear gradient fill; the linear gradient goes from green to blue to purple with a leading startPoint and trailing endPoint.

The gradient applies the color function along an axis, as defined by its start and end points. The gradient maps the unit-space points into the bounding rectangle of each shape filled with the gradient.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Initializer

init(gradient:startPoint:endPoint:) Creates a new linear gradient from the Gradient colors, the start, and the end.


Type Alias

Body The type of view representing the body of this view.