Home

Awesome

AutoLayoutKit

Version Platform Build Status Bitdeli Badge

Announcement: Manuscript

You think about using AutoLayoutKit in one of your shiny new swift-only Apps? Well, now you can.

Introducing Manuscript, the fancy successor of AutoLayoutKit written in pure Swift. (Carthage compatible, still under development)

Usage

For a very basic running example check out the example app. Clone the repo and run pod install from the Project directory first.

Let me give you a quick example on how easy it is to create NSLayoutConstraints in code using ALK.

[ALKConstraints layout:childView do:^(ALKConstraints *c) {
  [c make:ALKCenterX equalTo:self s:ALKCenterX];
  [c make:ALKCenterY equalTo:self s:ALKCenterY];
  [c set:ALKWidth to:30.f];
  [c set:ALKHeight to:30.f];
}];

Curious what the same code looks without ALK? Check out this.

New in Version 0.6.0: Convenience Methods

Entering Version 0.6.0, the basic sample from above can be improved even further.

[ALKConstraints layout:childView do:^(ALKConstraints *c) {
  [c centerIn:self];
  [c setSize:CGSizeMake(30.f, 30.f)];
}];

New in Version 1.0.0:

Using with Swift without optional chaining

ALKConstraints.layout(titleLabel) { c in
  c.make(.trailing, equalTo: self, s: .trailing, minus: 10)
}

Store newly created active constraint to block valiable

__block NSLayoutConstraint * heightConstraint = nil;
[ALKConstraints layout:self.view do:^(ALKConstraints * c) {
  heightConstraint = [c set:ALKHeight to:100.f];
}];
var leadingConstraint: NSLayoutConstraint? = nil
ALKConstraints.layout(titleLabel) { c in
  leadingConstraint = c.make(.leading, equalTo: self, s: .leading, plus: 10)
}

Using iOS 11 Safe Area

In case of iOS version less than 11, default make... methods will be used as fallback.

All Safe Area methods uses times value as 1.0.

[ALKConstraints layout:titleLabel do:^(ALKConstraints * c) {
  [c make:ALKLeading equalToSafeArea:self.view s:ALKLeading plus:8];
  [c make:ALKTrailing equalToSafeArea:self.view s:ALKTrailing minus:8];
}];
ALKConstraints.layout(titleLabel) { c in
  c.make(.leading, equalToSafeArea: self, s: .leading, plus: 8)
  c.make(.trailing, equalToSafeArea: self, s: .trailing, minus: 8)
}

Requirements

Installation

AutoLayoutKit is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "AutoLayoutKit"

Author

Florian Krueger, florian.krueger@projectserver.org

License

AutoLayoutKit is available under the MIT license. See the LICENSE file for more info.