A micro UIStackView convenience API inspired by SwiftUI

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


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