Structure

Path

The outline of a 2D shape.

Declaration

@frozen struct Path

Topics

Setting the Size of a View

func frame(width: CGFloat?, height: CGFloat?, alignment: Alignment) -> View

Positions this view within an invisible frame with the specified size.

func fixedSize() -> View

Fixes this view at its ideal size.

func fixedSize(horizontal: Bool, vertical: Bool) -> View

Fixes this view at its ideal size in the specified dimensions.

Specifying the Relative Size of a View

func layoutPriority(Double) -> View

Sets the priority by which a parent layout should apportion space to this child.

Setting the Position of a View

func position(CGPoint) -> View

Fixes the center of this view at the specified point in its parent’s coordinate space.

func position(x: CGFloat, y: CGFloat) -> View

Fixes the center of this view at the specified coordinates in its parent’s coordinate space.

func offset(CGSize) -> View

Offsets this view by the horizontal and vertical distances in the given size.

func offset(x: CGFloat, y: CGFloat) -> OffsetShape<Path>

Changes the relative position of this shape using the specified coordinates.

func edgesIgnoringSafeArea(Edge.Set) -> View

Extends the view out of the safe area on the specified edges.

Aligning Views

func alignmentGuide(HorizontalAlignment, computeValue: (ViewDimensions) -> CGFloat) -> View

Returns a view modified so that its value for the given guide is the result of passing the ViewDimensions of the underlying view to computeValue.

func alignmentGuide(VerticalAlignment, computeValue: (ViewDimensions) -> CGFloat) -> View

Returns a view modified so that its value for the given guide is the result of passing the ViewDimensions of the underlying view to computeValue.

Adjusting the Padding of a View

func padding(CGFloat) -> View

Pads this view along all edge insets by the amount you specify.

func padding(EdgeInsets) -> View

Pads this view using the edge insets you specify.

func padding(Edge.Set, CGFloat?) -> View

Pads this view using the edge insets you specify.

Setting the Foreground or Background of a View

Setting the Border of a View

func border<S>(S, width: CGFloat) -> View

Adds a border to this view with the specified style and width.

Masking and Clipping Views

func clipped(antialiased: Bool) -> View

Clips this view to its bounding rectangular frame.

func clipShape<S>(S, style: FillStyle) -> View

Sets a clipping shape for this view.

func cornerRadius(CGFloat, antialiased: Bool) -> View

Clips this view to its bounding frame, with the specified corner radius.

Scaling Views

Adjusting Text in a View

func font(Font?) -> View

Sets the default font for text in this view.

func lineLimit(Int?) -> View

Sets the maximum number of lines that text can occupy in this view.

func lineSpacing(CGFloat) -> View

Sets the amount of space between lines of text in this view.

func minimumScaleFactor(CGFloat) -> View

Sets the minimum amount that text in this view scales down to fit in the available space.

func truncationMode(Text.TruncationMode) -> View

Sets the truncation mode for lines of text that are too long to fit in the available space.

func allowsTightening(Bool) -> View

Sets whether text in this view can compress the space between characters when necessary to fit text in a line.

func flipsForRightToLeftLayoutDirection(Bool) -> View

Sets whether this view flips its contents horizontally when the layout direction is right-to-left.

Adding Animations to a View

func animation(Animation?) -> View

Applies the given animation to all animatable values within this view.

func animation<V>(Animation?, value: V) -> View

Applies the given animation to this view, whenever the specified value changes.

func transition(AnyTransition) -> View

Associates a transition with self.

Handling View Taps and Gestures

func itemProvider(Optional<() -> NSItemProvider?>) -> View

Provides a closure that vends the drag representation to be used for a particular DynamicContent.

func transaction((inout Transaction) -> Void) -> View

Applies the given transaction mutation function to all transactions used within the view.

Handling View Events

func onAppear(perform: (() -> Void)?) -> View

Adds an action to perform when this view appears.

func onDisappear(perform: (() -> Void)?) -> View

Adds an action to perform when this view disappears.

Handling View Hover and Focus

func onHover(perform: (Bool) -> Void) -> View

Adds an action to perform when the user moves the pointer over or away from this view’s frame.

func focusable(Bool, onFocusChange: (Bool) -> Void) -> View

Sets whether this view is focusable and, if so, adds an action to perform when the view comes into focus.

Supporting Drag and Drop in Views

func onDrag(() -> NSItemProvider) -> View

Activates this view as the source of a drag and drop operation.

func onDrop(of: [String], delegate: DropDelegate) -> View

Defines the destination for a drag and drop operation with the same size and position as this view, with behavior controlled by the given delegate.

func onDrop(of: [String], isTargeted: Binding<Bool>?, perform: ([NSItemProvider], CGPoint) -> Bool) -> View

Defines the destination for a drag and drop operation with the same size and position as this view, handling dropped content and the drop location with the given closure.

func onDrop(of: [String], isTargeted: Binding<Bool>?, perform: ([NSItemProvider]) -> Bool) -> View

Defines the destination for a drag and drop operation, using the same size and position as this view, handling dropped content with the given closure.

Adopting View Color Schemes

func colorScheme(ColorScheme) -> View

Sets this view’s color scheme.

func accentColor(Color?) -> View

Sets the accent color for this view and the views it contains.

Applying Blurs and Shadows to a View

Applying Graphical Effects to a View

func opacity(Double) -> View

Sets the transparency of this view.

func brightness(Double) -> View

Brightens this view by the specified amount.

func contrast(Double) -> View

Sets the contrast and separation between similar colors in this view.

func colorInvert() -> View

Inverts the colors in this view.

func colorMultiply(Color) -> View

Adds a color multiplication effect to this view.

func blendMode(BlendMode) -> View

Sets the blend mode for compositing this view with overlapping views.

func compositingGroup() -> View

Wraps this view in a compositing group.

func drawingGroup(opaque: Bool, colorMode: ColorRenderingMode) -> View

Composites this view’s contents into an offscreen image before final display.

func saturation(Double) -> View

Adjusts the color saturation of this view.

func grayscale(Double) -> View

Adds a grayscale effect to this view.

func hueRotation(Angle) -> View

Applies a hue rotation effect to this view.

func luminanceToAlpha() -> View

Adds a luminance to alpha effect to this view.

Configuring a List View

func listRowInsets(EdgeInsets?) -> View

Sets the inset to be applied to self in a List.

func listRowBackground<V>(V?) -> View

Sets the view to be placed behind self when placed in a List

func listRowPlatterColor(Color?) -> View

Sets the color to be apply to the system cell platter when self is placed in a List

Configuring Context Menu Views

func contextMenu<MenuItems>(ContextMenu<MenuItems>?) -> View

Attaches a ContextMenu and its children to self.

Configuring Touch Bar Views

func touchBar<Content>(TouchBar<Content>) -> View

Sets the TouchBar and its content to be shown in the Touch Bar when applicable

func touchBarItemPrincipal(Bool) -> View

Principal views have special significance to this TouchBar. Currently, that item will be placed in the center of the row.

func touchBarCustomizationLabel(Text) -> View

The user-visible String identifying the view’s functionality. Visible during user customization.

func touchBarItemPresence(TouchBarItemPresence) -> View

The behavior of the view when being customized by the user. Views may be:

Hiding and Disabling Views

func hidden() -> View

Hides this view.

func disabled(Bool) -> View

Adds a condition that controls whether users can interact with this view.

func deleteDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be deleted.

func moveDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be moved.

Setting View Preferences

func preference<K>(key: K.Type, value: K.Value) -> View

Returns a view producing value as the value of preference Key seen by its ancestors.

func transformPreference<K>(K.Type, (inout K.Value) -> Void) -> View

Returns a view that applies callback(&value) to the value of preference Key that’s seen by its ancestors.

Responding to View Preferences

func onPreferenceChange<K>(K.Type, perform: (K.Value) -> Void) -> View

Adds an action to perform when the specified preference key’s value changes.

func backgroundPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as as the background to self.

func overlayPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as an overlay on self.

Setting the Environment Values of a View

func environment<V>(WritableKeyPath<EnvironmentValues, V>, V) -> View

Returns a view wrapping self that sets a value for an environment keyPath.

func transformEnvironment<V>(WritableKeyPath<EnvironmentValues, V>, transform: (inout V) -> Void) -> View

Returns a view wrapping self that transforms the value of the environment key described by keyPath by applying a transform function.

Configuring a View for Hit Testing

func contentShape<S>(S, eoFill: Bool) -> View

Returns a new view that defines the content shape for hit-testing self as shape. eoFill defines whether the shape is interpreted using the even-odd winding number rule or not.

Configuring View Previews

func previewDevice(PreviewDevice?) -> View

Overrides the device for a preview.

func previewDisplayName(String?) -> View

Provides a user visible name shown in the editor.

func previewLayout(PreviewLayout) -> View

Overrides the size of the container for the preview.

Deprecated

func equatable() -> EquatableView<Path>

Returns a new view that will prevent self updating its child view when its new value is the same as its old value.

Initializers

init()

Creates an empty path.

init(CGMutablePath)

Creates a path from a copy of a mutable shape path.

init(CGPath)

Creates a path from an immutable shape path.

init((inout Path) -> ())

Creates an empty path, and then executes the closure to add the initial elements.

init(CGRect)

Creates a path as the given rectangle.

init(ellipseIn: CGRect)

Creates a path as an ellipse inscribed within the given rectangle.

Instance Properties

var boundingRect: CGRect

A rectangle containing all path segments.

var cgPath: CGPath

An immutable path representing the elements in the path.

var isEmpty: Bool

A Boolean value indicating whether the path contains zero elements.

Instance Methods

func addArc(tangent1End: CGPoint, tangent2End: CGPoint, radius: CGFloat, transform: CGAffineTransform)

Adds an arc of a circle to the path, specified with a radius and two tangent lines.

func addCurve(to: CGPoint, control1: CGPoint, control2: CGPoint)

Adds a cubic Bézier curve to the path, with the specified end point and control points.

func addLine(to: CGPoint)

Appends a straight line segment from the current point to the specified point.

func addLines([CGPoint])

Adds a sequence of connected straight-line segments to the path.

func addPath(Path, transform: CGAffineTransform)

Appends a copy of path to the path.

func addQuadCurve(to: CGPoint, control: CGPoint)

Adds a quadratic Bézier curve to the path, with the specified end point and control point.

func addRect(CGRect, transform: CGAffineTransform)

Adds a rectangular subpath to the path.

func addRects([CGRect], transform: CGAffineTransform)

Adds a sequence of rectangular subpaths to the path.

func addRelativeArc(center: CGPoint, radius: CGFloat, startAngle: Angle, delta: Angle, transform: CGAffineTransform)

Adds an arc of a circle to the path, specified with a radius and a difference in angle.

func applying(CGAffineTransform) -> Path

Returns a path constructed by applying the transform to all points of the path.

func closeSubpath()

Closes and completes the current subpath.

func contains(CGPoint, eoFill: Bool) -> Bool

Returns true if the path contains a specified point.

func defaultWheelPickerItemHeight(CGFloat) -> View

Sets the default .wheel style Picker item height within self.

func digitalCrownRotation<V>(Binding<V>) -> View

Tracks Digital Crown rotations by updating the given binding.

func forEach((Path.Element) -> Void)

Calls body with each element in the path.

func move(to: CGPoint)

Begins a new subpath at the specified point.

func offset(CGSize) -> OffsetShape<Path>

Changes the relative position of this shape using the specified size.

func offset(CGPoint) -> OffsetShape<Path>

Changes the relative position of this shape using the specified point.

func offsetBy(dx: CGFloat, dy: CGFloat) -> Path

Returns a path constructed by translating self by (dx, dy).

func rotation(Angle, anchor: UnitPoint) -> RotatedShape<Path>

Rotates this shape around an anchor point at the angle you specify.

func scale(CGFloat, anchor: UnitPoint) -> ScaledShape<Path>

Scales this shape without changing its bounding frame.

func scale(x: CGFloat, y: CGFloat, anchor: UnitPoint) -> ScaledShape<Path>

Scales this shape without changing its bounding frame.

func strokedPath(StrokeStyle) -> Path

Returns a stroked copy of the path using style to define how the stroked outline is created.

func tag<V>(V) -> View

Sets the tag of the view, used for selecting from a list of View options.

func transform(CGAffineTransform) -> TransformedShape<Path>

Applies an affine transform to this shape.

func trimmedPath(from: CGFloat, to: CGFloat) -> Path

Returns a partial copy of the path.

Operator Functions

static func != (Path, Path) -> Bool

Returns a Boolean value indicating whether two values are not equal.

Enumerations

enum Path.Element

An element of a path.

Relationships

See Also

Shapes

struct Rectangle

A rectangular shape aligned inside the frame of the view containing it.

enum Edge

An enumeration to indicate one edge of a rectangle.

struct RoundedRectangle

A rectangular shape with rounded corners, aligned inside the frame of the view containing it.

struct Circle

A circle centered on the frame of the view containing it.

struct Ellipse

An ellipse aligned inside the frame of the view containing it.

struct Capsule

A capsule shape aligned inside the frame of the view containing it.