
Early this year I mentioned a library called Keep Layout designed to make Auto Layout easy to use from code.
Florian Kugler has created a library called FLKAutoLayout allowing you to easily set up auto layout using a nice readable syntax, simple predicated statements (ie. “>=300, <=500″) and with some extra features for more complicated layouts.
Here’s a code example from the readme demonstrating how easy it is to use FLKAutoLayout:
[labels[0] alignTop:@"20" leading:@"20" toView:labels[0].superview];
// give it a minimum width of 200 and a maximum width of 300
[labels[0] constrainWidth:@">=200,<=300"];
// now constrain all labels to this size
[UIView alignLeadingAndTrailingEdgesOfViews:labels];
// space the labels out vertically with 10 points in between
[UIView spaceOutViewsVertically:labels predicate:@"10"];
// now let’s take care of the text fields.
// the first one has a fixed space of 20 to its label
[textFields[0] constrainLeadingSpaceToView:labels[0] predicate:@"20"];
// constrain the right edge to its superview with 20 points padding
[textFields[0] alignTrailingEdgeWithView:textFields[0].superview predicate:@"20"];
// constrain all other text fields to the same width
[UIView alignLeadingAndTrailingEdgesOfViews:textFields];
// and finally let’s align the baseline of each label with the baseline of each text field
[UIView alignAttribute:NSLayoutAttributeBaseline ofViews:labels toViews:textFields predicate:nil];
You can download FLKAutoLayout on Github here.
You’ll find a nice usage example included.
A very nice library for creating complex layouts with concise and readable code.
- Library Making iOS 6 Auto-Layout Extremely Easy To Use Programmatically
- Open Source Library For Bringing The iOS 6 Auto Layout API To iOS 5
- Open Source Library Using ReactiveCocoa Providing An Alternative To iOS 6′s Auto Layout
- Tutorial: How To Create Great Looking Layouts With UICollectionView
- Example: Using UICollectionViewFlowLayout To Easily Create Great Looking Scrollable Grid Layouts
Original article: Open Source Library For Easily Creating Complex Auto Layout Layouts From Code
©2013 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.