Clicky

iOS Dev Nugget 136 Auto Layout with Cartography

.

Need to run a code review on your codebase? Hire me

If you write code using Auto Layout, you will have noticed by now that the structure of the code from using NSLayoutConstraint isn't that readable once you have a few more UI elements.

Cartography by Robb Böhnke changes that by introducing a declarative manner to specify Auto Layout constraints in Swift.

This is an example given in the README:

layout(view1, view2) { view1, view2 in
    view1.width   == (view1.superview!.width - 50) * 0.5
    view2.width   == view1.width - 50
    view1.height  == 40
    view2.height  == view1.height
    view1.centerX == view1.superview!.centerX
    view2.centerX == view1.centerX

    view1.top >= view1.superview!.top + 20
    view2.top == view1.bottom + 20
}

Check it out.

If you are working with Objective C, also look at FLKAutoLayout by Florian Kugler.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues