<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Shape",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5ShapeP"
  },
  "title" : "Shape"
}
-->

# Shape

A 2D shape that you can use when drawing a view.

```
nonisolated protocol Shape : Sendable, Animatable, View
```

## Overview

Shapes without an explicit fill or stroke get a default fill based on the
foreground color.

You can define shapes in relation to an implicit frame of reference, such as
the natural size of the view that contains it. Alternatively, you can define
shapes in terms of absolute coordinates.

## Topics

### Getting standard shapes

[`buttonBorder`](/documentation/SwiftUI/Shape/buttonBorder)

A shape that defers to the environment to determine the resolved button border shape.

[`capsule`](/documentation/SwiftUI/Shape/capsule)

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

[`capsule(style:)`](/documentation/SwiftUI/Shape/capsule(style:))

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

[`circle`](/documentation/SwiftUI/Shape/circle)

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

[`containerRelative`](/documentation/SwiftUI/Shape/containerRelative)

A shape that is replaced by an inset version of the current
container shape. If no container shape was defined, is replaced by
a rectangle.

[`ellipse`](/documentation/SwiftUI/Shape/ellipse)

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

[`textInputBorder`](/documentation/SwiftUI/Shape/textInputBorder)

A shape that defers to the environment to determine the resolved
text input border shape.

### Getting rectangles

[`rect`](/documentation/SwiftUI/Shape/rect)

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

[`rect(cornerRadii:style:)`](/documentation/SwiftUI/Shape/rect(cornerRadii:style:))

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

[`rect(cornerRadius:style:)`](/documentation/SwiftUI/Shape/rect(cornerRadius:style:))

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

[`rect(corners:isUniform:)`](/documentation/SwiftUI/Shape/rect(corners:isUniform:))

Creates a rectangle with the same corner style set on four corners.

[`rect(cornerSize:style:)`](/documentation/SwiftUI/Shape/rect(cornerSize:style:))

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

[`rect(topLeadingCorner:topTrailingCorner:bottomLeadingCorner:bottomTrailingCorner:)`](/documentation/SwiftUI/Shape/rect(topLeadingCorner:topTrailingCorner:bottomLeadingCorner:bottomTrailingCorner:))

Creates a rectangle with individual styles for each corner.

[`rect(topLeadingRadius:bottomLeadingRadius:bottomTrailingRadius:topTrailingRadius:style:)`](/documentation/SwiftUI/Shape/rect(topLeadingRadius:bottomLeadingRadius:bottomTrailingRadius:topTrailingRadius:style:))

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

[`rect(uniformBottomCorners:topLeadingCorner:topTrailingCorner:)`](/documentation/SwiftUI/Shape/rect(uniformBottomCorners:topLeadingCorner:topTrailingCorner:))

Creates a rectangle with a corner style set on the two bottom corners
uniformly, and two other styles for the two top corners respectively.

[`rect(uniformLeadingCorners:topTrailingCorner:bottomTrailingCorner:)`](/documentation/SwiftUI/Shape/rect(uniformLeadingCorners:topTrailingCorner:bottomTrailingCorner:))

Creates a rectangle with a corner style uniformly set on the two
leading corners, and two other styles for the two trailing corners
respectively.

[`rect(uniformLeadingCorners:uniformTrailingCorners:)`](/documentation/SwiftUI/Shape/rect(uniformLeadingCorners:uniformTrailingCorners:))

Creates a rectangle with a corner style uniformly set on the two
leading corners, and another style uniformly set on the two trailing
corners.

[`rect(uniformTopCorners:bottomLeadingCorner:bottomTrailingCorner:)`](/documentation/SwiftUI/Shape/rect(uniformTopCorners:bottomLeadingCorner:bottomTrailingCorner:))

Creates a rectangle with a corner style uniformly set on the two top
corners, and two other styles for the bottom two corners respectively.

[`rect(uniformTopCorners:uniformBottomCorners:)`](/documentation/SwiftUI/Shape/rect(uniformTopCorners:uniformBottomCorners:))

Creates a rectangle with a corner style uniformly set on the two top
corners, and another style uniformly set on the two bottom corners.

[`rect(uniformTrailingCorners:topLeadingCorner:bottomLeadingCorner:)`](/documentation/SwiftUI/Shape/rect(uniformTrailingCorners:topLeadingCorner:bottomLeadingCorner:))

Creates a rectangle with a corner style uniformly set on the two
trailing corners, and two other styles for the two leading corners
respectively.

### Defining a shape’s size and path

[`sizeThatFits(_:)`](/documentation/SwiftUI/Shape/sizeThatFits(_:))

Returns the size of the view that will render the shape, given
a proposed size.

[`path(in:)`](/documentation/SwiftUI/Shape/path(in:))

Describes this shape as a path within a rectangular frame of reference.

### Transforming a shape

[`trim(from:to:)`](/documentation/SwiftUI/Shape/trim(from:to:))

Trims this shape by a fractional amount based on its representation as a
path.

[`transform(_:)`](/documentation/SwiftUI/Shape/transform(_:))

Applies an affine transform to this shape.

[`size(_:)`](/documentation/SwiftUI/Shape/size(_:))

Returns a new version of self representing the same shape, but
that will ask it to create its path from a rect of `size`. This
does not affect the layout properties of any views created from
the shape (e.g. by filling it).

[`size(_:anchor:)`](/documentation/SwiftUI/Shape/size(_:anchor:))

Returns a new version of self representing the same shape, but
within a rect of `size` instead of the container size.

[`size(width:height:)`](/documentation/SwiftUI/Shape/size(width:height:))

Returns a new version of self representing the same shape, but
that will ask it to create its path from a rect of size
`(width, height)`. This does not affect the layout properties
of any views created from the shape (e.g. by filling it).

[`size(width:height:anchor:)`](/documentation/SwiftUI/Shape/size(width:height:anchor:))

Returns a new version of self representing the same shape, but
within a rect of `(width, height)` instead of the container size.

[`scale(_:anchor:)`](/documentation/SwiftUI/Shape/scale(_:anchor:))

Scales this shape without changing its bounding frame.

[`scale(x:y:anchor:)`](/documentation/SwiftUI/Shape/scale(x:y:anchor:))

Scales this shape without changing its bounding frame.

[`rotation(_:anchor:)`](/documentation/SwiftUI/Shape/rotation(_:anchor:))

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

[`offset(_:)`](/documentation/SwiftUI/Shape/offset(_:))

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

[`offset(x:y:)`](/documentation/SwiftUI/Shape/offset(x:y:))

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

### Setting the stroke characteristics

[`stroke(_:lineWidth:)`](/documentation/SwiftUI/Shape/stroke(_:lineWidth:))

Traces the outline of this shape with a color or gradient.

[`stroke(_:lineWidth:antialiased:)`](/documentation/SwiftUI/Shape/stroke(_:lineWidth:antialiased:))

Traces the outline of this shape with a color or gradient.

[`stroke(lineWidth:)`](/documentation/SwiftUI/Shape/stroke(lineWidth:))

Returns a new shape that is a stroked copy of `self` with
line-width defined by `lineWidth` and all other properties of
`StrokeStyle` having their default values.

[`stroke(_:style:)`](/documentation/SwiftUI/Shape/stroke(_:style:))

Traces the outline of this shape with a color or gradient.

[`stroke(_:style:antialiased:)`](/documentation/SwiftUI/Shape/stroke(_:style:antialiased:))

Traces the outline of this shape with a color or gradient.

[`stroke(style:)`](/documentation/SwiftUI/Shape/stroke(style:))

Returns a new shape that is a stroked copy of `self`, using the
contents of `style` to define the stroke characteristics.

### Filling a shape

[`fill(_:style:)`](/documentation/SwiftUI/Shape/fill(_:style:))

Fills this shape with a color or gradient.

[`fill(style:)`](/documentation/SwiftUI/Shape/fill(style:))

Fills this shape with the foreground color.

### Setting the role

[`role`](/documentation/SwiftUI/Shape/role)

An indication of how to style a shape.

### Indicating a layout direction

[`layoutDirectionBehavior`](/documentation/SwiftUI/Shape/layoutDirectionBehavior)

Returns the behavior this shape should use for different layout
directions.

### Performing operations on a shape

[`intersection(_:eoFill:)`](/documentation/SwiftUI/Shape/intersection(_:eoFill:))

Returns a new shape with filled regions common to both shapes.

[`lineIntersection(_:eoFill:)`](/documentation/SwiftUI/Shape/lineIntersection(_:eoFill:))

Returns a new shape with a line from this shape that overlaps the
filled regions of the given shape.

[`lineSubtraction(_:eoFill:)`](/documentation/SwiftUI/Shape/lineSubtraction(_:eoFill:))

Returns a new shape with a line from this shape that does not
overlap the filled region of the given shape.

[`subtracting(_:eoFill:)`](/documentation/SwiftUI/Shape/subtracting(_:eoFill:))

Returns a new shape with filled regions from this shape that are
not in the given shape.

[`symmetricDifference(_:eoFill:)`](/documentation/SwiftUI/Shape/symmetricDifference(_:eoFill:))

Returns a new shape with filled regions either from this shape or
the given shape, but not in both.

[`union(_:eoFill:)`](/documentation/SwiftUI/Shape/union(_:eoFill:))

Returns a new shape with filled regions in either this shape or
the given shape.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)