Instance Method

frame(minWidth:idealWidth:maxWidth:minHeight:idealHeight:maxHeight:alignment:)

Positions this view within an invisible frame having the specified size constraints.

Declaration

func frame(minWidth: CGFloat? = nil, idealWidth: CGFloat? = nil, maxWidth: CGFloat? = nil, minHeight: CGFloat? = nil, idealHeight: CGFloat? = nil, maxHeight: CGFloat? = nil, alignment: Alignment = .center) -> some View

Parameters

minWidth

The minimum width for the resulting frame.

idealWidth

The ideal width for the resulting frame.

maxWidth

The maximum width for the resulting frame.

minHeight

The minimum height for the resulting frame.

idealHeight

The ideal height for the resulting frame.

maxHeight

The maximum height for the resulting frame.

alignment

The alignment of this view inside the resulting frame. alignment applies if this view is smaller than the size given by the resulting frame. Note that most alignment values have no apparent effect when the size of the frame happens to match that of this view.

Return Value

A view with flexible dimensions given by the call’s non-nil parameters.

Discussion

Always specify at least one size characteristic when calling this method. Pass nil or leave out a characteristic to indicate that the frame should adopt this view’s sizing behavior, constrained by the other non-nil arguments.

The size proposed to this view is the size proposed to the frame, limited by any constraints specified, and with any ideal dimensions specified replacing any corresponding unspecified dimensions in the proposal.

If no minimum or maximum constraint is specified in a given dimension, the frame adopts the sizing behavior of its child in that dimension. If both constraints are specified in a dimension, the frame unconditionally adopts the size proposed for it, clamped to the constraints. Otherwise, the size of the frame in either dimension is:

  • If a minimum constraint is specified and the size proposed for the frame by the parent is less than the size of this view, the proposed size, clamped to that minimum.

  • If a maximum constraint is specified and the size proposed for the frame by the parent is greater than the size of this view, the proposed size, clamped to that maximum.

  • If a maximum constraint is specified and the size proposed for the frame by the parent is greater than the size of this view, the proposed size, clamped to that maximum.

  • Otherwise, the size of this view.

See Also

Sizing a View

func frame(width: CGFloat?, height: CGFloat?, alignment: Alignment) -> View

Positions this view within an invisible frame with the specified size.

func fixedSize() -> View

Fixes this view at its ideal size.

func fixedSize(horizontal: Bool, vertical: Bool) -> View

Fixes this view at its ideal size in the specified dimensions.

func layoutPriority(Double) -> View

Sets the priority by which a parent layout should apportion space to this child.