Stacks

A micro UIStackView convenience API inspired by SwiftUI.

let stack: UIView = .hStack(alignment: .center, margins: .all(16), [
    .vStack(spacing: 8, [
        titleLabel,
        subtitleLabel
    ]),
    .spacer(minLength: 16),
    star
])
  • Concise syntax inspired by SwiftUI
  • Your code matches the created view hierarchy
  • Spacers automatically adjust to the stack view axis
  • Margins automatically enable isLayoutMarginsRelativeArrangement

Screen Shot 2021-04-16 at 13 36 02

UIEdgeInsets extensions are not included.

extension UIEdgeInsets {
    static func all(_ value: CGFloat) -> UIEdgeInsets {
        UIEdgeInsets(top: value, left: value, bottom: value, right: value)
    }

    init(v: CGFloat, h: CGFloat) {
        self = UIEdgeInsets(top: v, left: h, bottom: v, right: h)
    }
}

For more layout goodness, check out Align.

GitHub

https://github.com/kean/Stacks