<!--
{
  "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

[`static var buttonBorder: ButtonBorderShape`](/documentation/SwiftUI/Shape/buttonBorder)

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

[`static var capsule: Capsule`](/documentation/SwiftUI/Shape/capsule)

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

[`static func capsule(style: RoundedCornerStyle) -> Self`](/documentation/SwiftUI/Shape/capsule(style:))

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

[`static var circle: Circle`](/documentation/SwiftUI/Shape/circle)

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

[`static var containerRelative: ContainerRelativeShape`](/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.

[`static var ellipse: Ellipse`](/documentation/SwiftUI/Shape/ellipse)

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

[`static var textInputBorder: TextInputBorderShape`](/documentation/SwiftUI/Shape/textInputBorder)

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

### Getting rectangles

[`static var rect: Rectangle`](/documentation/SwiftUI/Shape/rect)

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

[`static func rect(cornerRadii: RectangleCornerRadii, style: RoundedCornerStyle) -> Self`](/documentation/SwiftUI/Shape/rect(cornerRadii:style:))

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

[`static func rect(cornerRadius: CGFloat, style: RoundedCornerStyle) -> Self`](/documentation/SwiftUI/Shape/rect(cornerRadius:style:))

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

[`static func rect(corners: Edge.Corner.Style, isUniform: Bool) -> Self`](/documentation/SwiftUI/Shape/rect(corners:isUniform:))

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

[`static func rect(cornerSize: CGSize, style: RoundedCornerStyle) -> Self`](/documentation/SwiftUI/Shape/rect(cornerSize:style:))

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

[`static func rect(topLeadingCorner: Edge.Corner.Style, topTrailingCorner: Edge.Corner.Style, bottomLeadingCorner: Edge.Corner.Style, bottomTrailingCorner: Edge.Corner.Style) -> Self`](/documentation/SwiftUI/Shape/rect(topLeadingCorner:topTrailingCorner:bottomLeadingCorner:bottomTrailingCorner:))

Creates a rectangle with individual styles for each corner.

[`static func rect(topLeadingRadius: CGFloat, bottomLeadingRadius: CGFloat, bottomTrailingRadius: CGFloat, topTrailingRadius: CGFloat, style: RoundedCornerStyle) -> Self`](/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.

[`static func rect(uniformBottomCorners: Edge.Corner.Style, topLeadingCorner: Edge.Corner.Style, topTrailingCorner: Edge.Corner.Style) -> Self`](/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.

[`static func rect(uniformLeadingCorners: Edge.Corner.Style, topTrailingCorner: Edge.Corner.Style, bottomTrailingCorner: Edge.Corner.Style) -> Self`](/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.

[`static func rect(uniformLeadingCorners: Edge.Corner.Style, uniformTrailingCorners: Edge.Corner.Style) -> Self`](/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.

[`static func rect(uniformTopCorners: Edge.Corner.Style, bottomLeadingCorner: Edge.Corner.Style, bottomTrailingCorner: Edge.Corner.Style) -> Self`](/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.

[`static func rect(uniformTopCorners: Edge.Corner.Style, uniformBottomCorners: Edge.Corner.Style) -> Self`](/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.

[`static func rect(uniformTrailingCorners: Edge.Corner.Style, topLeadingCorner: Edge.Corner.Style, bottomLeadingCorner: Edge.Corner.Style) -> Self`](/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

[`func sizeThatFits(ProposedViewSize) -> CGSize`](/documentation/SwiftUI/Shape/sizeThatFits(_:))

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

[`func path(in: CGRect) -> Path`](/documentation/SwiftUI/Shape/path(in:))

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

### Transforming a shape

[`func trim(from: CGFloat, to: CGFloat) -> some Shape`](/documentation/SwiftUI/Shape/trim(from:to:))

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

[`func transform(CGAffineTransform) -> TransformedShape<Self>`](/documentation/SwiftUI/Shape/transform(_:))

Applies an affine transform to this shape.

[`func size(CGSize) -> some Shape`](/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).

[`func size(CGSize, anchor: UnitPoint) -> some Shape`](/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.

[`func size(width: CGFloat, height: CGFloat) -> some Shape`](/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).

[`func size(width: CGFloat, height: CGFloat, anchor: UnitPoint) -> some Shape`](/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.

[`func scale(CGFloat, anchor: UnitPoint) -> ScaledShape<Self>`](/documentation/SwiftUI/Shape/scale(_:anchor:))

Scales this shape without changing its bounding frame.

[`func scale(x: CGFloat, y: CGFloat, anchor: UnitPoint) -> ScaledShape<Self>`](/documentation/SwiftUI/Shape/scale(x:y:anchor:))

Scales this shape without changing its bounding frame.

[`func rotation(Angle, anchor: UnitPoint) -> RotatedShape<Self>`](/documentation/SwiftUI/Shape/rotation(_:anchor:))

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

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

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

[`func offset(x: CGFloat, y: CGFloat) -> OffsetShape<Self>`](/documentation/SwiftUI/Shape/offset(x:y:))

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

### Setting the stroke characteristics

[`func stroke<S>(S, lineWidth: CGFloat) -> some View`](/documentation/SwiftUI/Shape/stroke(_:lineWidth:))

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

[`func stroke<S>(S, lineWidth: CGFloat, antialiased: Bool) -> StrokeShapeView<Self, S, EmptyView>`](/documentation/SwiftUI/Shape/stroke(_:lineWidth:antialiased:))

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

[`func stroke(lineWidth: CGFloat) -> some Shape`](/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.

[`func stroke<S>(S, style: StrokeStyle) -> some View`](/documentation/SwiftUI/Shape/stroke(_:style:))

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

[`func stroke<S>(S, style: StrokeStyle, antialiased: Bool) -> StrokeShapeView<Self, S, EmptyView>`](/documentation/SwiftUI/Shape/stroke(_:style:antialiased:))

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

[`func stroke(style: StrokeStyle) -> some Shape`](/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

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

Fills this shape with a color or gradient.

[`func fill(style: FillStyle) -> some View`](/documentation/SwiftUI/Shape/fill(style:))

Fills this shape with the foreground color.

### Setting the role

[`static var role: ShapeRole`](/documentation/SwiftUI/Shape/role)

An indication of how to style a shape.

### Indicating a layout direction

[`var layoutDirectionBehavior: LayoutDirectionBehavior`](/documentation/SwiftUI/Shape/layoutDirectionBehavior)

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

### Performing operations on a shape

[`func intersection<T>(T, eoFill: Bool) -> some Shape`](/documentation/SwiftUI/Shape/intersection(_:eoFill:))

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

[`func lineIntersection<T>(T, eoFill: Bool) -> some Shape`](/documentation/SwiftUI/Shape/lineIntersection(_:eoFill:))

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

[`func lineSubtraction<T>(T, eoFill: Bool) -> some Shape`](/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.

[`func subtracting<T>(T, eoFill: Bool) -> some Shape`](/documentation/SwiftUI/Shape/subtracting(_:eoFill:))

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

[`func symmetricDifference<T>(T, eoFill: Bool) -> some Shape`](/documentation/SwiftUI/Shape/symmetricDifference(_:eoFill:))

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

[`func union<T>(T, eoFill: Bool) -> some Shape`](/documentation/SwiftUI/Shape/union(_:eoFill:))

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

## Relationships

### Conforming Types

[`Path`](/documentation/SwiftUI/Path)

[`ContainerRelativeShape`](/documentation/SwiftUI/ContainerRelativeShape)

[`OffsetShape`](/documentation/SwiftUI/OffsetShape)

[`DefaultGlassEffectShape`](/documentation/SwiftUI/DefaultGlassEffectShape)

[`TextInputBorderShape`](/documentation/SwiftUI/TextInputBorderShape)

[`AnyShape`](/documentation/SwiftUI/AnyShape)

[`ConcentricRectangle`](/documentation/SwiftUI/ConcentricRectangle)

[`ScaledShape`](/documentation/SwiftUI/ScaledShape)

[`Ellipse`](/documentation/SwiftUI/Ellipse)

[`RotatedShape`](/documentation/SwiftUI/RotatedShape)

[`ButtonBorderShape`](/documentation/SwiftUI/ButtonBorderShape)

[`TransformedShape`](/documentation/SwiftUI/TransformedShape)

[`RoundedRectangle`](/documentation/SwiftUI/RoundedRectangle)

[`Capsule`](/documentation/SwiftUI/Capsule)

[`UnevenRoundedRectangle`](/documentation/SwiftUI/UnevenRoundedRectangle)

[`Circle`](/documentation/SwiftUI/Circle)

[`Rectangle`](/documentation/SwiftUI/Rectangle)

### Inherited By

[`InsettableShape`](/documentation/SwiftUI/InsettableShape)

[`RoundedRectangularShape`](/documentation/SwiftUI/RoundedRectangularShape)

### Inherits From

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

[`Animatable`](/documentation/SwiftUI/Animatable)

[`View`](/documentation/SwiftUI/View)

---

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)