How To Setup Basic Auto Layout

Published Mar 01, 2017
How To Setup Basic Auto Layout

What Is Auto Layout Used For?

Auto layout is used for developers who are creating iPhone/iPad apps for devices with different screen sizes. You will need this for most of the apps you develop, so it is a very useful thing to know how to do that properly.

The Basics

Auto layout is all about constraints. If you wanted a button in the middle on the screen, you would need set constraints that center the image vertically and horizontally.

The button would now appear in the middle of the screen for all devices.

The Different Terms And What They Mean

  • Align – Create alignment constraints, such as aligning the left edges of two views.
  • Pin – Create spacing constraints, such as defining the width of a UI control.
  • Issues – Resolve layout issues.
  • Stack – Embed views into a stack view. Stack view is a new feature since Xcode 7. We will further discuss about it in the next chapter.

What are the Cons of Auto Layout?

"I think Apple has done a poor job of explaining the mechanism. So when you first start using auto layout, the process seems arbitrary and the outcomes are unpredictable.

You describe an interface screen by placing elements, and having these elements placed relative to each other by way of constraints. Think of these constraints as springs or rubber bands. The layout engine will iterate through all these constraints until it finds a solution in which they are all satisfied. This is very flexible and powerful. But that kind of power allows you to make spectacular mistakes." , Glyn Williams

Credits

Terms, https://www.appcoda.com/auto-layout-guide/

Cons, https://www.quora.com/profile/Glyn-Williams

Discover and read more posts from victor klawitter
get started