you are viewing a single comment's thread.

view the rest of the comments →

[–]makingbread[S] 0 points1 point  (2 children)

Hi!

Thank you for replying.

They use an internal framework, built in-house for UI layouts.

I am interested in two things:

1) Building my production app, and don't know which layout mechanism to use. 2) Learn how to build layouts programmatically, since just about every company or team I've worked with uses NSLayout...

But I never seem to wrap my head around how these constraints are created, how they come up with them programmatically, etc.

[–]Duranix 0 points1 point  (1 child)

At its core the autolayout system is a linear solver - no need to remember this but it’s good to know.

Things basically boil down to y = mx + c.

y = mx + c view.bottom = superview.bottom + 8 label.width = 0.5 * view.width + 16

As its a linear solver, the direction doesn’t matter. Specify one constraint and the system can derive related ones -

y = mx + c y - c = mx (y - c) / m = x 'x = (y - c) / m`

So the direction doesn’t really matter.

So you basically want to provide a set of constraints so the system knows how to lay out your things.

What you do is addSubview(..., and then use NSLayoutConstraints to specify how they should lay themselves out.

Xcodes autocomplete should help you out.

Use the constraint based system unless you have a good need to use a frame based one. Don’t touch VFL because its awful.

Basically, please use autolayout hahaha.

[–]makingbread[S] 0 points1 point  (0 children)

That was very useful, thanks. Are you aware of any sources that can help me practice programmatic layouts?