Get Updates By E-mail 

Article Written By:
Johann Dowa

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.

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.