Search code examples
iosuser-interfaceautolayoutpixel

ios programmatic UI versus autolayout best practices


I'm trying to understand the best practices on layout out UI in ios. Specifically, I'm try to understand the advantages / disadvantages between: pure programmatic UI, Storyboarding and XIBs, and auto-layout in ios 6.0+.

I'm used to pure programmatic UI (no auto-layout) but I'm trying to understand where I could potentially have problems. Are fractional coordinates a problem? Would I have to deal with a lot of conditionals to deal with different ios screen sizes or could I just take care of that in code with percentages.

I've seen a few threads on this on stackoverflow but nothing comprehensive enough.


Solution

  • The end product is the same regardless of if you've added the constraints in code or in interface builder. You don't have to deal with fractional coordinates or, in most cases, different screen sizes - that's pretty much the point of Autolayout.

    In Xcode 4, editing constraints in interface builder was terrible. It's much improved in Xcode 5. However, if you're used to generating your UI in code, then I'd recommend carrying on the same way as you transition to Autolayout.

    If you're interested I have written a series of blog posts on Autolayout, covering interface builder, visual format language, individual creation of constraints and my Autolayout helper category greatly simplifies building layouts in code.