user3492165
user3492165

Reputation: 99

Creating a UI programmatically in iOS and autolayout?

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.

Upvotes: 0

Views: 1239

Answers (1)

sergio
sergio

Reputation: 69027

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.

Upvotes: 3

Related Questions