Classes

The following classes are available globally.

  • A base class for layouts. This layout does not require a view at runtime unless a configuration block has been provided.

    See more

    Declaration

    Swift

    open class BaseLayout<V: View>
  • Layout for a UIButton.

    Since UIKit does not provide threadsafe methods to determine the size of a button given its content it’s implememtation hard-codes the current observed style of UIButton. If the style of UIButton changes in the future, then the current implementation will need to be updated to reflect the new style.

    If future-proofing is a concern for your application, then you should not use ButtonLayout and instead implement your own custom layout that uses you own custom button view (e.g. by subclassing UIControl).

    Similary, if you have your own custom button view, you will need to create your own custom layout for it.

    See more

    Declaration

    Swift

    open class ButtonLayout<Button: UIButton>: BaseLayout<Button>, ConfigurableLayout
  • A UICollectionView that retains and uses a ReloadableViewLayoutAdapter as its delegate and data source.

    See more

    Declaration

    Swift

    open class LayoutAdapterCollectionView: UICollectionView
  • A UITableView that retains and uses a ReloadableViewLayoutAdapter as its delegate and data source.

    See more

    Declaration

    Swift

    open class LayoutAdapterTableView: UITableView
  • Manages background layout for reloadable views, including UICollectionView and UITableView.

    Set it as a UICollectionView or UITableView’s dataSource and delegate.

    See more

    Declaration

    Swift

    open class ReloadableViewLayoutAdapter: NSObject, ReloadableViewUpdateManagerDelegate
  • 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))
    
    See more

    Declaration

    Swift

    open class SizeLayout<V: View>: BaseLayout<V>, ConfigurableLayout
  • A layout that stacks sublayouts along an axis.

    Axis space is allocated to sublayouts according to the distribution policy.

    If this not enough space along the axis for all sublayouts then layouts with the highest flexibility are removed until there is enough space to posistion the remaining layouts.

    See more

    Declaration

    Swift

    open class StackLayout<V: View>: BaseLayout<V>
  • A view that stacks its subviews along a single axis.

    It is similar to UIStackView except that it uses StackLayout instead of Auto Layout, which means layout is much faster.

    Although StackView is faster than UIStackView, it still does layout on the main thread. If you want to get the full benefit of LayoutKit, use StackLayout directly.

    Unlike UIStackView, if you position StackView with Auto Layout, you must call invalidateIntrinsicContentSize on that StackView whenever any of its subviews’ intrinsic content sizes change (e.g. changing the text of a UILabel that is positioned by the StackView). Otherwise, Auto Layout won’t recompute the layout of the StackView.

    Subviews MUST implement sizeThatFits so StackView can allocate space correctly. If a subview uses Auto Layout, then the subview may implement sizeThatFits by calling systemLayoutSizeFittingSize.

    See more

    Declaration

    Swift

    open class StackView: UIView