sizeThatFits
Swift declarationnonisolated func sizeThatFits(_ proposal: ProposedViewSize) -> CGSizeReturns the original proposal, with nil components replaced by a small positive value.
protocol · iOS 13.0+ · SDK 27.1
nonisolated protocol Shape : Sendable, Animatable, ViewA 2D shape that you can use when drawing a view. 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.
nonisolated func sizeThatFits(_ proposal: ProposedViewSize) -> CGSizeReturns the original proposal, with nil components replaced by a small positive value.
nonisolated var layoutDirectionBehavior: LayoutDirectionBehavior { get }Returns the behavior this shape should use for different layout directions. If the layoutDirectionBehavior for a Shape is one that mirrors, the shape's path will be mirrored horizontally when in the specified layout direction. When mirrored, the individual points of the path will be transformed. Defaults to `.mirrors` when deploying on iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0 and later, and to `.fixed` if not. To mirror a path when deploying to earlier releases, either use `View.flipsForRightToLeftLayoutDirection` for a filled or stroked shape or conditionally mirror the points in the path of the shape.
nonisolated var body: _ShapeView<Self, ForegroundStyle> { get }nonisolated func size(width: CGFloat, height: CGFloat, anchor: UnitPoint) -> some Shape
Returns a new version of self representing the same shape, but within a rect of `(width, height)` instead of the container size. The `anchor` parameter determines how the shape will be positioned within the container when the path's bounds and the container's bounds are not equal. This does not affect the layout properties of any views created from the shape (e.g. by filling it). - Parameters: - width: The width to constrain the shape to. - height: The height to constrain the shape to. - anchor: The anchor to use to determine how to position the new shape. - Returns: A new shape constrained to the given `size`, and positioned using `anchor`.
nonisolated func size(width: CGFloat, height: CGFloat) -> some Shape
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).
nonisolated func size(_ size: CGSize, anchor: UnitPoint) -> some Shape
Returns a new version of self representing the same shape, but within a rect of `size` instead of the container size. The `anchor` parameter determines how the shape will be positioned within the container when the path's bounds and the container's bounds are not equal. This does not affect the layout properties of any views created from the shape (e.g. by filling it). - Parameters: - size: The size to constrain the shape to. - anchor: The anchor to use to determine how to position the new shape. - Returns: A new shape constrained to the given `size`, and positioned using `anchor`.
nonisolated func size(_ size: CGSize) -> some Shape
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).
nonisolated func trim(from startFraction: CGFloat = 0, to endFraction: CGFloat = 1) -> some Shape
Trims this shape by a fractional amount based on its representation as a path. To create a `Shape` instance, you define the shape's path using lines and curves. Use the `trim(from:to:)` method to draw a portion of a shape by ignoring portions of the beginning and ending of the shape's path. For example, if you're drawing a figure eight or infinity symbol (∞) starting from its center, setting the `startFraction` and `endFraction` to different values determines the parts of the overall shape. The following example shows a simplified infinity symbol that draws only three quarters of the full shape. That is, of the two lobes of the symbol, one lobe is complete and the other is half complete. Path { path in path.addLines([ .init(x: 2, y: 1), .init(x: 1, y: 0), .init(x: 0, y: 1), .init(x: 1, y: 2), .init(x: 3, y: 0), .init(x: 4, y: 1), .init(x: 3, y: 2), .init(x: 2, y: 1) ]) } .trim(from: 0.25, to: 1.0) .scale(50, anchor: .topLeading) .stroke(Color.black, lineWidth: 3) Changing the parameters of `trim(from:to:)` to `.trim(from: 0, to: 1)` draws the full infinity symbol, while `.trim(from: 0, to: 0.5)` draws only the left lobe of the symbol. - Parameters: - startFraction: The fraction of the way through drawing this shape where drawing starts. - endFraction: The fraction of the way through drawing this shape where drawing ends. - Returns: A shape built by capturing a portion of this shape's path.
nonisolated func offset(x: CGFloat = 0, y: CGFloat = 0) -> OffsetShape<Self>Changes the relative position of this shape using the specified point. The following example renders two circles. It places one circle at its default position. The second circle is outlined with a stroke, positioned on top of the first circle and offset by 100 points to the left and 50 points below. Circle() .overlay( Circle() .offset(x: -100, y: 50) .stroke() ) - Parameters: - x: The horizontal amount, in points, by which you offset the shape. Negative numbers are to the left and positive numbers are to the right. - y: The vertical amount, in points, by which you offset the shape. Negative numbers are up and positive numbers are down. - Returns: A shape offset by the specified amount.
nonisolated func offset(_ offset: CGSize) -> OffsetShape<Self>Changes the relative position of this shape using the specified size. The following example renders two circles. It places one circle at its default position. The second circle is outlined with a stroke, positioned on top of the first circle and offset by 100 points to the left and 50 points below. Circle() .overlay( Circle() .offset(CGSize(width: -100, height: 50)) .stroke() ) - Parameter offset: The amount, in points, by which you offset the shape. Negative numbers are to the left and up; positive numbers are to the right and down. - Returns: A shape offset by the specified amount.
nonisolated func stroke(style: StrokeStyle) -> some Shape
Returns a new shape that is a stroked copy of `self`, using the contents of `style` to define the stroke characteristics.
nonisolated func stroke(lineWidth: CGFloat = 1) -> some Shape
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.
38 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
Shape.role
Static protocol requirements cannot be called through an instance.
Shape.rect
Static protocol requirements cannot be called through an instance.
Shape.rect(cornerSize:style:)
Static protocol requirements cannot be called through an instance.
Shape.rect(cornerRadius:style:)
Static protocol requirements cannot be called through an instance.
Shape.rect(cornerRadii:style:)
Static protocol requirements cannot be called through an instance.
Shape.rect(topLeadingRadius:bottomLeadingRadius:bottomTrailingRadius:topTrailingRadius:style:)
Static protocol requirements cannot be called through an instance.
Shape.capsule
Static protocol requirements cannot be called through an instance.
Shape.capsule(style:)
Static protocol requirements cannot be called through an instance.
Shape.ellipse
Static protocol requirements cannot be called through an instance.
Shape.circle
Static protocol requirements cannot be called through an instance.
Shape.intersection(_:eoFill:)
The iOS SDK compiler rejected this binding: 'some' types are only permitted in properties, subscripts, and functions
Shape.union(_:eoFill:)
The iOS SDK compiler rejected this binding: 'some' types are only permitted in properties, subscripts, and functions
Shape.subtracting(_:eoFill:)
The iOS SDK compiler rejected this binding: 'some' types are only permitted in properties, subscripts, and functions
Shape.symmetricDifference(_:eoFill:)
The iOS SDK compiler rejected this binding: 'some' types are only permitted in properties, subscripts, and functions
Shape.lineIntersection(_:eoFill:)
The iOS SDK compiler rejected this binding: 'some' types are only permitted in properties, subscripts, and functions
Shape.lineSubtraction(_:eoFill:)
The iOS SDK compiler rejected this binding: 'some' types are only permitted in properties, subscripts, and functions
Shape.rect(corners:isUniform:)
Static protocol requirements cannot be called through an instance.
Shape.rect(topLeadingCorner:topTrailingCorner:bottomLeadingCorner:bottomTrailingCorner:)
Static protocol requirements cannot be called through an instance.
Shape.rect(uniformTopCorners:uniformBottomCorners:)
Static protocol requirements cannot be called through an instance.
Shape.rect(uniformLeadingCorners:uniformTrailingCorners:)
Static protocol requirements cannot be called through an instance.
Shape.rect(uniformTopCorners:bottomLeadingCorner:bottomTrailingCorner:)
Static protocol requirements cannot be called through an instance.
Shape.rect(uniformBottomCorners:topLeadingCorner:topTrailingCorner:)
Static protocol requirements cannot be called through an instance.
Shape.rect(uniformLeadingCorners:topTrailingCorner:bottomTrailingCorner:)
Static protocol requirements cannot be called through an instance.
Shape.rect(uniformTrailingCorners:topLeadingCorner:bottomLeadingCorner:)
Static protocol requirements cannot be called through an instance.
Shape.containerRelative
Static protocol requirements cannot be called through an instance.
Shape.offset(_:)
The iOS SDK compiler rejected this binding: member 'offset' cannot be used on value of type 'any Shape'; consider using a generic constraint instead [#ExistentialMemberAccess]
Shape.scale(x:y:anchor:)
The iOS SDK compiler rejected this binding: member 'scale' cannot be used on value of type 'any Shape'; consider using a generic constraint instead [#ExistentialMemberAccess]
Shape.scale(_:anchor:)
The iOS SDK compiler rejected this binding: member 'scale' cannot be used on value of type 'any Shape'; consider using a generic constraint instead [#ExistentialMemberAccess]
Shape.rotation(_:anchor:)
The iOS SDK compiler rejected this binding: member 'rotation' cannot be used on value of type 'any Shape'; consider using a generic constraint instead [#ExistentialMemberAccess]
Shape.transform(_:)
The iOS SDK compiler rejected this binding: member 'transform' cannot be used on value of type 'any Shape'; consider using a generic constraint instead [#ExistentialMemberAccess]