Skip to content

Instantly share code, notes, and snippets.

@cjnevin
Created October 23, 2022 01:00
Show Gist options
  • Save cjnevin/08e31e5ee307df918ddb9232bbf7bd47 to your computer and use it in GitHub Desktop.
Save cjnevin/08e31e5ee307df918ddb9232bbf7bd47 to your computer and use it in GitHub Desktop.
public protocol ConstraintBuilding {
var anchorable: Anchorable { get }
func build(
_ anchor: Anchor,
constant: CGFloat,
multiplier: CGFloat
) -> ConstraintBuilder
}
extension ConstraintBuilding {
public func leading(_ constant: CGFloat = 0, multiplier: CGFloat = 1) -> ConstraintBuilder {
build(anchorable.anchor(.leading), constant: constant, multiplier: multiplier)
}
public func trailing(_ constant: CGFloat = 0, multiplier: CGFloat = 1) -> ConstraintBuilder {
build(anchorable.anchor(.trailing), constant: constant, multiplier: multiplier)
}
public func top(_ constant: CGFloat = 0, multiplier: CGFloat = 1) -> ConstraintBuilder {
build(anchorable.anchor(.top), constant: constant, multiplier: multiplier)
}
public func bottom(_ constant: CGFloat = 0, multiplier: CGFloat = 1) -> ConstraintBuilder {
build(anchorable.anchor(.bottom), constant: constant, multiplier: multiplier)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment