Open Source Library For Easily Creating Complex Auto Layout Layouts From Code

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:

// align the first label with its superview
[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:@"&gt;=200,&lt;=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.

FacebookTwitterDiggStumbleUponGoogle Plus

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.

Leave a Reply

Your email address will not be published. Required fields are marked *