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.

3

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.