Autolayout improvements

Ok, well not really improvements to auto layout on iOS, but improvements in my understanding of Auto Layout. The biggest thing I learned is that it is easier to setup and manage constraints in code, then to try and use Storyboards to define and modify the constraints.

If you have not used AutoLayout, Apple recommends that you start with doing it in Interface Builder. I find that this is not necessarily easier, and in my mind, it seems that using the code based method is much easier. The second thing I found was that the Visual Forma language is very powerful and easy to use. For example @”[self(<=128@800, >=64@800)]” indicates that the object has a minimum width of 64 points and maximum width of 128 points withe a priority of 800. You can set relationships between objects and to themselves. By doing this, you can setup very dynamic layouts that automatically resize and will adjust certain constraints over others. The priority, lower numbers == lower priority. 1000 is maximum priority and 0 is the minimum.

A great way of thinking about constraints is to think of constraints of the object on itself, then in relationship to things around it, and finally in regard to the entire view. If you’ve not watched the WWDC sessions from 2012 and 2013 on Autolayout, go watch them now! They are fantastic.

About Michael

I created this site to help showcase the mobile application community in the Research Triangle Park area of North Carolina.
Tagged , . Bookmark the permalink.

Comments are closed.