Getting started with Cocoa’s new auto layout

Auto layout might be the most exciting Mac only thing announced at WWDC this year. It improves on Cocoa’s idea of springs and struts and will let spend way less time building your UI.

Despite seeing auto layout used at WWDC, I couldn’t remember how to use it a couple months later when I sat down to play with it. Apple’s programming guide has lots of good stuff, but it seems to be missing a bit about getting started.

Default projects in Xcode 4.1 on 10.7 don’t default to using  auto layout so you’ll need to enable it. (Note: Projects using auto layout are 10.7 only)

So now you can use auto layout in your project. How do you use auto layout? By adding constraints. You’ll add constraints from the editor menu.

You can also command+click on multiple controls and add constraints to more than one control at a time.

Here’s a short screencast of some simple things you can do with constraints. One great thing is that they work inside Xcode and you don’t need to build and run your app.

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>