StackView

open class StackView : View

A view that lays out a set of its arranged subviews horizontally or vertically automatically.

  • List of views contained within this stack view that are being arranged as part of the stack view’s layout behaviour.

    Declaration

    Swift

    private(set) public var arrangedSubviews: [View] { get }
  • Intrinsic size of a StackView is always UISize.zero, as the default behaviour of a stack view is to always shrink to the smallest size possible.

    Declaration

    Swift

    public override var intrinsicSize: UISize? { get }
  • A spacing applied between every view added to this stack view. This value is override by custom per-view spacings specified with self.setCustomSpacing(after:_:).

    Declaration

    Swift

    open var spacing: Double { get set }
  • The orientation the arranged views within this stack view will be laid.

    Declaration

    Swift

    open var orientation: Orientation { get set }
  • The alignment of the arranged views within this stack view perpendicular to the current orientation.

    By default, stack views shrink to occupy the smallest space that can fit all arranged views, and that can lead to empty slack space along the opposite axis the views are aligned on, and this property can be used to specify how each view is placed along that empty space.

    Defaults to Alignment.leading.

    Seealso

    Alignment.

    Declaration

    Swift

    open var alignment: Alignment { get set }
  • Inset space between the edges of the stack view and its arranged subviews.

    Declaration

    Swift

    open var contentInset: UIEdgeInsets { get set }
  • Initializes a new empty stack view with a given starting orientation.

    Declaration

    Swift

    public init(orientation: Orientation)
  • Inserts a view to the list of arranged views at a specified index.

    Arranged views are added as subviews as well, and are further subject to the stack view’s layout behaviour.

    Precondition

    index >= 0 && index < arrangedSubviews.count.

    Declaration

    Swift

    open func insertArrangedSubview(_ view: View, at index: Int)
  • Adds a view to the end of the arranged view list on this stack view.

    Arranged views are added as subviews as well, and are further subject to the stack view’s layout behaviour.

    Declaration

    Swift

    open func addArrangedSubview(_ view: View)
  • Adds a list of views to the end of the arranged view list on this stack view.

    Arranged views are added as subviews as well, and are further subject to the stack view’s layout behaviour.

    Declaration

    Swift

    open func addArrangedSubviews(_ views: [View])
  • Removes an arranged view at a specified index from this stack view.

    Removing an arranged view also removes it from the view hierarchy.

    Declaration

    Swift

    open func removeArrangedSubview(atIndex index: Int)
  • Removes all arranged views from this stack view.

    Removing arranged views also remove them from the view hierarchy.

    Declaration

    Swift

    open func removeArrangedSubviews()
  • Declaration

    Swift

    open override func willRemoveSubview(_ view: View)
  • Sets a custom spacing after a specified view when it is being arranged in this stack view.

    Custom spacings override the default StackView.spacing that is applied uniformly across all views.

    Passing nil as a spacing removes any custom spacing configured for the view in this stack view.

    Spacings can be added before or after a view is added to the arranged views list on a stack view.

    Declaration

    Swift

    open func setCustomSpacing(after view: View, _ spacing: Double?)
  • Specifies the orientation that views from a stack view are laid out.

    See more

    Declaration

    Swift

    public enum Orientation
  • Specifies the alignment behaviour of arranged subviews of a stack view along the perpendicular axis of the stack view’s orientation, i.e. the horizontal alignment of a vertical stack of views, and vice-versa for a vertical alignment of a horizontal stack of views.

    See more

    Declaration

    Swift

    public enum Alignment