Shape

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

ProtocoliOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+Shape in SwiftUI

Declaration

React
type Shape =
  | 'buttonBorder'
  | 'capsule'
  | 'circle'
  | 'containerRelative'
  | 'ellipse'
  | 'rect'
  | 'textInputBorder'
  | { capsule: { style: RoundedCornerStyle; }; }
  | { rect: { cornerRadii: RectangleCornerRadii; style?: RoundedCornerStyle; }; }
  | { rect: { cornerRadius: number; style?: RoundedCornerStyle; }; }
  | { rect: { corners: EdgeCornerStyle; isUniform?: boolean; }; }
  | { rect: { cornerSize: CGSize; style?: RoundedCornerStyle; }; }
  | { rect: { topLeadingCorner: EdgeCornerStyle; topTrailingCorner: EdgeCornerStyle; bottomLeadingCorner: EdgeCornerStyle; bottomTrailingCorner: EdgeCornerStyle; }; }
  | { rect: { topLeadingRadius?: number; bottomLeadingRadius?: number; bottomTrailingRadius?: number; topTrailingRadius?: number; style?: RoundedCornerStyle; }; }
  | { rect: { uniformBottomCorners: EdgeCornerStyle; topLeadingCorner: EdgeCornerStyle; topTrailingCorner: EdgeCornerStyle; }; }
  | { rect: { uniformLeadingCorners: EdgeCornerStyle; topTrailingCorner: EdgeCornerStyle; bottomTrailingCorner: EdgeCornerStyle; }; }
  | { rect: { uniformLeadingCorners: EdgeCornerStyle; uniformTrailingCorners: EdgeCornerStyle; }; }
  | { rect: { uniformTopCorners: EdgeCornerStyle; bottomLeadingCorner: EdgeCornerStyle; bottomTrailingCorner: EdgeCornerStyle; }; }
  | { rect: { uniformTopCorners: EdgeCornerStyle; uniformBottomCorners: EdgeCornerStyle; }; }
  | { rect: { uniformTrailingCorners: EdgeCornerStyle; topLeadingCorner: EdgeCornerStyle; bottomLeadingCorner: EdgeCornerStyle; }; }
  | ButtonBorderShape
  | Capsule
  | Circle
  | ConcentricRectangle
  | ContainerRelativeShape
  | DefaultGlassEffectShape
  | Ellipse
  | InsettableShape
  | Path
  | Rectangle
  | RoundedRectangle
  | RoundedRectangularShape
  | ShapeChain
  | ShapeDeclaration
  | TextInputBorderShape
  | UnevenRoundedRectangle;
Swift
nonisolated protocol Shape : Sendable, Animatable, View

Pass a literal, or build one with SwiftUI.Shape from import { SwiftUI } from 'swiftui-react-native'.

Type properties

  • 'buttonBorder'SwiftUI.Shape.buttonBorder

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

  • 'capsule'SwiftUI.Shape.capsule

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

  • 'circle'SwiftUI.Shape.circle

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

  • 'containerRelative'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'SwiftUI.Shape.ellipse

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

  • 'rect'SwiftUI.Shape.rect

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

  • 'textInputBorder'SwiftUI.Shape.textInputBorder

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

Type methods

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.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Drawing and shapes.