One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

ProposedViewSize

struct · iOS 16.0+ · SDK 27.1

@frozen struct ProposedViewSize

A proposal for the size of a view. During layout in SwiftUI, views choose their own size, but they do that in response to a size proposal from their parent view. When you create a custom layout using the ``Layout`` protocol, your layout container participates in this process using `ProposedViewSize` instances. The layout protocol's methods take a proposed size input that you can take into account when arranging views and calculating the size of the composite container. Similarly, your layout proposes a size to each of its own subviews when it measures and places them. Layout containers typically measure their subviews by proposing several sizes and looking at the responses. The container can use this information to decide how to allocate space among its subviews. A layout might try the following special proposals: * The ``zero`` proposal; the view responds with its minimum size. * The ``infinity`` proposal; the view responds with its maximum size. * The ``unspecified`` proposal; the view responds with its ideal size. A layout might also try special cases for one dimension at a time. For example, an ``HStack`` might measure the flexibility of its subviews' widths, while using a fixed value for the height.

Members (10)

get · iOS 16.0+

unspecified

TypeScript
static get unspecified(): ProposedViewSize
Swift declaration
static let unspecified: ProposedViewSize

The proposed size with both dimensions left unspecified. Both dimensions contain `nil` in this size proposal. Subviews of a custom layout return their ideal size when you propose this value using the ``LayoutSubview/dimensions(in:)`` method. A custom layout should also return its ideal size from the ``Layout/sizeThatFits(proposal:subviews:cache:)`` method for this value.

method · iOS 16.0+

replacingUnspecifiedDimensions

TypeScript
replacingUnspecifiedDimensions(size?: { width: number; height: number }): { width: number; height: number }
Swift declaration
func replacingUnspecifiedDimensions(by size: CGSize = CGSize(width: 10, height: 10)) -> CGSize

Creates a new proposal that replaces unspecified dimensions in this proposal with the corresponding dimension of the specified size. Use the default value to prevent a flexible view from disappearing into a zero-sized frame, and ensure the unspecified value remains visible during debugging. - Parameter size: A set of concrete values to use for the size proposal in place of any unspecified dimensions. The default value is `10` for both dimensions. - Returns: A new, fully specified size proposal.

get · iOS 16.0+

zero

TypeScript
static get zero(): ProposedViewSize
Swift declaration
static let zero: ProposedViewSize

A size proposal that contains zero in both dimensions. Subviews of a custom layout return their minimum size when you propose this value using the ``LayoutSubview/dimensions(in:)`` method. A custom layout should also return its minimum size from the ``Layout/sizeThatFits(proposal:subviews:cache:)`` method for this value.

get · iOS 16.0+

width

TypeScript
get width(): (number) | null
Swift declaration
var width: CGFloat?

The proposed horizontal size measured in points. A value of `nil` represents an unspecified width proposal, which a view interprets to mean that it should use its ideal width.

set · iOS 16.0+

width

TypeScript
set width(value: (number) | null)
Swift declaration
var width: CGFloat?

The proposed horizontal size measured in points. A value of `nil` represents an unspecified width proposal, which a view interprets to mean that it should use its ideal width.

init · iOS 16.0+

init

TypeScript
static initWidthHeight(width?: (number) | null, height?: (number) | null): ProposedViewSize
Swift declaration
init(width: CGFloat?, height: CGFloat?)

Creates a new proposed size using the specified width and height. - Parameters: - width: A proposed width in points. Use a value of `nil` to indicate that the width is unspecified for this proposal. - height: A proposed height in points. Use a value of `nil` to indicate that the height is unspecified for this proposal.

get · iOS 16.0+

height

TypeScript
get height(): (number) | null
Swift declaration
var height: CGFloat?

The proposed vertical size measured in points. A value of `nil` represents an unspecified height proposal, which a view interprets to mean that it should use its ideal height.

set · iOS 16.0+

height

TypeScript
set height(value: (number) | null)
Swift declaration
var height: CGFloat?

The proposed vertical size measured in points. A value of `nil` represents an unspecified height proposal, which a view interprets to mean that it should use its ideal height.

get · iOS 16.0+

infinity

TypeScript
static get infinity(): ProposedViewSize
Swift declaration
static let infinity: ProposedViewSize

A size proposal that contains infinity in both dimensions. Both dimensions contain <doc://com.apple.documentation/documentation/CoreFoundation/swift/floatingpoint/infinity> in this size proposal. Subviews of a custom layout return their maximum size when you propose this value using the ``LayoutSubview/dimensions(in:)`` method. A custom layout should also return its maximum size from the ``Layout/sizeThatFits(proposal:subviews:cache:)`` method for this value.

init · iOS 16.0+

init

TypeScript
static init(size: { width: number; height: number }): ProposedViewSize
Swift declaration
init(_ size: CGSize)

Creates a new proposed size from a specified size. - Parameter size: A proposed size with dimensions measured in points.

Skipped declarations

No declarations were skipped in this snapshot.

All SwiftUICore types →