Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
/ MiniLayout Public archive

Minimal AutoLayout convenience layer. Program constraints succinctly. ⚠️ Moved into https://github.com/yonat/SweeterSwift

License

Notifications You must be signed in to change notification settings

yonat/MiniLayout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniLayout

Minimal AutoLayout convenience layer. Program constraints succinctly.

Swift Version Build Status License CocoaPods Compatible
Platform PRs Welcome

Usage

Put label over textField

// using MiniLayout:
view.constrain(label, at: .leading, to: textField)
view.constrain(textField, at: .top, to: label, at: .bottom, diff: 8)
 
// without MiniLayout:
view.addConstraint( NSLayoutConstraint(item: label, attribute: .leading, relatedBy: .equal, toItem: textField, attribute: .leading, multiplier: 1, constant: 0) )
view.addConstraint( NSLayoutConstraint(item: textField, attribute: .top, relatedBy: .equal, toItem: label, attribute: .bottom, multiplier: 1, constant: 8) )

Add button at the center of view

// using MiniLayout:
view.addConstrainedSubview(button, constrain: .centerX, .centerY)
 
// without MiniLayout:
view.addSubview(button)
button.setTranslatesAutoresizingMaskIntoConstraints(false)
view.addConstraint( NSLayoutConstraint(item: button, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0) )
view.addConstraint( NSLayoutConstraint(item: button, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1, constant: 0) )

Add child view controller covering all but the bottom margin

// using MiniLayout:
addConstrainedChild(vc, constrain: .bottomMargin, .top, .left, .right)
 
// without MiniLayout:
addChild(vc)
view.addSubview(vc.view)
vc.view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.addConstraint( NSLayoutConstraint(item: vc.view, attribute: .bottomMargin, relatedBy: .equal, toItem: view, attribute: .bottomMargin, multiplier: 1, constant: 0) )
view.addConstraint( NSLayoutConstraint(item: vc.view, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 0) )
view.addConstraint( NSLayoutConstraint(item: vc.view, attribute: .left, relatedBy: .equal, toItem: view, attribute: .left, multiplier: 1, constant: 0) )
view.addConstraint( NSLayoutConstraint(item: vc.view, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1, constant: 0) )
vc.didMove(toParent: self)

Installation

Manually:

Add MiniLayout.swift to your project.

Using CocoaPods:

pod 'MiniLayout'

Legacy versions:

Swift version MiniLayout version
4.0 (Xcode 9.4) pod 'MiniLayout', '~> 1.2.1'
3 pod 'MiniLayout', '~> 1.1.0'
2.3 pod 'MiniLayout', '~> 1.0.1'

Meta

@yonatsharon

https://github.com/yonat/MiniLayout

About

Minimal AutoLayout convenience layer. Program constraints succinctly. ⚠️ Moved into https://github.com/yonat/SweeterSwift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published