Skip to content
openbakeryPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

PinLayout

PinLayout is a helper for creating auto layout contraints.

LayoutBuilder API Cheatsheet

Basics

let subview = UIView()
self.view.addSubview(subview)

self.subview.layout
	.pin(.top, .leading)
	.width(100)
	.centerX()

Edges

Layout.Edge values: .top, .bottom, .leading, .trailing (plus whatever Layout.Edge defines).

Method Purpose
fill() Pin all four edges (.leading, .trailing, .top, .bottom) — fills the superview.
pin(_ edges: Layout.Edge...) Pin edges with no gap.
pin(_ edges:, insets:, gap:, priority:, relatedBy:) Pin edges with per-edge insets (NSDirectionalEdgeInsets), a fallback gap, priority, and relation (.equal, .greaterThanOrEqual, …).
pin(_ edges:, insets:, gap: Layout.Defaults, priority:) Gap resolved from the layout's default value for that edge.
pin(_ edge:, to otherView: UIView, gap:, priority:) Pin one edge to another view's corresponding edge.
pin(_ edge:, to otherView:, gap: Layout.Defaults, priority:) Same, with a library default gap.

Centering

Method Purpose
centerX(offset:, priority:) Center horizontally in superview, with offset.
centerX(to otherView:) Center horizontally relative to another view.
centerY(offset:, priority:) Center vertically in superview, with offset.
centerY(to otherView:) Center vertically relative to another view.
center() Both centerX + centerY in superview.
center(to otherView:) Both centers relative to another view.

Size

Method Purpose
width(_ constant:, priority:) Fixed width.
height(_ constant:, priority:) Fixed height.
minWidth(_ constant:) / minHeight(_ constant:) Minimum size constraints.
equalWidthAndHeight(priority:) Width == height (aspect ratio 1:1).
equalWidth(with other:, priority:, multiplier:, constant:) Width equal (or proportional) to another view.
equalHeight(with other:, priority:, multiplier:, constant:) Height equal (or proportional) to another view.
equalSize(with other:, priority:, multiplier:) Both width and height equal to another view.

Alignment

Method Purpose
align(with otherView:, to edge:, gap:) Align this view's edge with another view's edge.

Constraint Recording (testing / teardown)

Method Purpose
startRecording(recorder:) Begin recording created constraints.
stopRecording() Stop recording.
finishRecording() -> [NSLayoutConstraint] Stop and return all recorded constraints.
findConstraint(attribute: Layout.Constant) -> NSLayoutConstraint? Look up a constraint by attribute.
removeAllConstraints() Remove all constraints from the view.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages