Auto Layout in iOS

Deniz Yüce
3 min readJun 18, 2022

--

In this article I wanted to describe what is Auto Layout basically and where it is used in your applications.

Basically I can summarize Auto Layout in one sentence:

When the size of your view changes, items you gave constraints act accordingly to those constraints.

For example when there is a 10 point constraint from superview’s top to your items top, it acts accordingly during size change. That is what Auto Layout does. Based on constraints placed on the views, Auto Layout determines the size and location of every view in your view hierarchy dynamically. As Apple Developer library says, this constraint-based approach allows you build interfaces that dynamically respond to both external and internal changes.

Some external changes:

  • Resizing the window (OS X).
  • Entering Split view on iPad (iOS).
  • Rotating the device (iOS).

These changes occur usually at runtime, and require dynamic response. Also we need to know that Auto Layout is a key component for supporting Slide Over and Split Views on the iPad.

Some internal changes:

  • Displayed content changes.
  • The app supports internationalization.
  • The app supports Dynamic Type (iOS).

Content change may arise the need of new layout. For example when the displayed text length changes, or displayed number of pictures in a collage changes the app can need a new layout.

Internationalization makes your app adapt to different languages, regions, and cultures. And it creates three effects on layout.

First, when you switch languages some word may be longer or shorter than your preferred language.For example, while German words are usually longer, Japanese words are generally shorter.

Secondly, depending on your region the representation of dates in your application can require a change.

And lastly, while changing languages some languages can require a different type of layout. For example when English has a left-to-right layout, while Arabic has right-to-left.

Also if your app supports Dynamic Type it means your user can change the font size used in your app. And you need to make your apps layout adapt accordingly.

This is the basic concept of Auto Layout. In my later articles I am going to be writting about how Auto Layout uses Constraints and Anatomy of a Constraint. I would like to do these as a series of Understanding Auto Layout.

Thank you for reading!

Source :

--

--