0

I am new to iOS programming and I have been building the UI for an app entirely programmatically. (I deleted the storyboard file + removed a property from the plist file and have been purely doing it through the code.) I want to understand for certain, in iOS7, is autolayout still occurring automatically? Or is this not the case?

Secondly, how can I manage it entirely programmatically? AKA, I have a nice interface for portrait mode. However when I go to landscape, it is obvious the UI is not adjusting properly. This makes me think autolayout is not on or it is not using proper constraints.

Is it suggested that I actually use interface builder instead?

Thanks.

user3492165
  • 99
  • 1
  • 9
  • possible duplicate of [Implementing auto layout for views generated programmatically](http://stackoverflow.com/questions/12593153/implementing-auto-layout-for-views-generated-programmatically) – Martin R Apr 08 '14 at 07:32
  • Did you follow this guide? https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/AutoLayoutinCode/AutoLayoutinCode.html – Alexis Apr 08 '14 at 07:34
  • And I strongly suggest you to use the storyboards :) It will help you preview your view in landscape mode. Even if you have a storyboard you can still add subviews and components programmatically. – Alexis Apr 08 '14 at 07:36

1 Answers1

3

I want to understand for certain, in iOS7, is autolayout still occurring automatically? Or is this not the case?

There are two ways to use auto layout: you can set it inside your storyboard, or you can define it programmatically. If you do not do either, auto layout is not applied.

how can I manage it entirely programmatically?

As the comments above suggest, have a look a Apple Docs as a start. There are also a couple of frameworks on github to make things easier, e.g., Masonry, but you will need anyway some understanding of how auto layout works.

Is it suggested that I actually use interface builder instead?

This could be a highly opinionated issue. It depends entirely on whether you prefer using Interface Builder or not. IB makes possible setting the constraints visually, but it is still not a trivial task, especially if your UI is a complex one. If you do it programmatically, you will have more code (and ugly code, at that). IB will also not fix "conflicts" between constraints, but it will make easier testing your constraints. But if you prefer defining things visually, vs. programmatically, IB is a good choice.

Linus Unnebäck
  • 23,234
  • 15
  • 74
  • 89
sergio
  • 68,819
  • 11
  • 102
  • 123
  • Additionally, I have one more quick question. Is autolayout intended to solve scaling issues related to: Varying screen sizes, portrait versus landscape, Font sizes in System settings ? Anything else? Thank you. – user3492165 Apr 10 '14 at 04:53
  • 1
    Definitely, all you mention is addressed by auto layout. BTW, rotation, screen size, etc., could be also solved via autoresizing masks (plus some view wrapping). The real novelty in auto layout is that it is more powerful and expressive than autoresizing masks and once you get used to it you can hopefully build more advanced UIs in a simple way. So, another big benefit of auto layout is that it allows you to get more precise control on your UI, deciding easily what is "fixed" at a "local" level, and what should adapt. Hope this helps. – sergio Apr 10 '14 at 07:53