open class SizeLayout<V: View>: BaseLayout<V>, ConfigurableLayout

A layout that has size constraints.

Default behavior

Alignment along a dimension defaults to .fill if there is no maximum constraint along that dimension and .center otherwise.

Flexibility along a dimension defaults to .inflexible if there is an exact constraint on that dimension, and .defaultFlex otherwise.

Constraint precedence

Constraints are enforced with the following precedence: 1. The maxSize paremeter of measurement. 2. The SizeLayout’s maxSize 3. The SizeLayout’s minSize

In other words, if it is impossible to satisfy all constraints simultaneously then constraints are broken starting with minSize.

Use cases

Some common use cases:

// A fixed size UIImageView.
SizeLayout<UIImageView>(width: 50, height: 50)

// A 1px tall divider that fills the width of its parent.
SizeLayout<UIView>(height: 1)

// A label with maximum width.
SizeLayout<UIView>(maxWidth: 100, sublayout: LabelLayout(text: "Spills onto two lines"))

// A label with minimum width.
SizeLayout<UIView>(minWidth: 100, sublayout: LabelLayout(text: "Hello", alignment: .fill))
  • Declaration


    open func measurement(within maxSize: CGSize) -> LayoutMeasurement



    The maximum size available to the layout.

    Return Value

    The minimum size required by the layout and its sublayouts given a maximum size. The size of the layout MUST NOT exceed maxSize.

  • Declaration


    open func arrangement(within rect: CGRect, measurement: LayoutMeasurement) -> LayoutArrangement



    The rectangle that the layout must position itself in.


    A measurement which has size less than or equal to rect.size and greater than or equal to measurement.maxSize.

    Return Value

    A complete set of frames for the layout.