Skip to content

Auto Layout convenience with minimal API surface area, but high expressive power

License

Notifications You must be signed in to change notification settings

vadimtrifonov/ConstraintProxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Constraint Proxy

Auto Layout convenience with minimal API surface area, but high expressive power

Features

  • Minimal API accessible through constraint proxy
  • Direct access to created NSLayoutConstraint
  • UILayoutGuide support
  • New UILayoutPriority constants including .maxNonRequired (999) for resolving layout ambiguities
  • translatesAutoresizingMaskIntoConstraints is automatically set to false on a target

Usage

Edges

subview.constraint.edges(to: view)

subview.constraint.edges(to: view, insets: .uniform(10))

subview.constraint.edges(excluding: .bottom, to: view, insets: .horizontal(10))

subview.constraint.edges(.bottom, .leading, to: view, insets: .leading(10))

Horizontal axis

subview.constraint.trailing(to: view)

subview.constraint.centerX(to: view)

subview.constraint.leading(to: view, .centerX)

subview.constraint.trailing(to: view, .leading, constant: 10)

Vertical axis

subview.constraint.bottom(to: view)

subview.constraint.centerY(to: view)

subview.constraint.top(to: view, .centerY)

subview.constraint.bottom(to: view, .top, constant: 10)

subview.constraint.lastBaseline(to: view)

Center

subview.constraint.center(to: view)

Size

subview.constraint.size(CGSize(width: 75, height: 75))

subview.constraint.size(to: view)

subview.constraint.size(to: view, multiplier: 0.5)

Dimension

subview.constraint.width(to: view)

subview.constraint.height(to: view, .width)

subview.constraint.height(to: view, multiplier: 0.5)

subview.constraint.width(constant: 50)

subview.constraint.height(constant: 75)

Layout guide

UIView and UILayoutGuide can be used interchangeably.

subview.constraint.edges(to: view.layoutMarginsGuide)
subview.constraint.lastBaseline(to: view.safeAreaLayoutGuide, .bottom)
subview.constraint.width(to: view.readableContentGuide)

Relation

Allmost all constraint methods have relation parameter.

subview.constraint.leading(to: view, relation: .greaterThanOrEqual)

Priority

All constraint methods have priority parameter.

subview.constraint.leading(to: view, priority: .defaultLow)

Activation

Constraints are created active by default. All constraint methods have active parameter to opt out of this.

subview.constraint.leading(to: view, active: false)

Installation

Requirements

  • iOS 11.0
  • Swift 5.0

Carthage

github "vadimtrifonov/ConstraintProxy"

About

Auto Layout convenience with minimal API surface area, but high expressive power

Resources

License

Stars

Watchers

Forks

Packages

No packages published