Git Product home page Git Product logo

autolayoutfundamentals-basics's Introduction

Auto Layout Fundamentals: Basics

Author: Bart Jacobs

Apple introduced Auto Layout several years ago during WWDC. Before the introduction of Auto Layout, developers programmatically laid out the user interface, positioning views by defining their frames and autoresizing masks.

The downside of this approach is obvious. Every view in the view hierarchy needed to be positioned and the positions recalculated for every change, such as a rotation of the device. Before Auto Layout, that was the only option for developers.

Auto Layout is a layout system that is descriptive and built on constraints. The developer tells the layout engine how to lay out the user interface. Instead of telling the layout engine that a button needs to be positioned at a specific location, the developer describes where it should be positioned.

A layout is defined by constraints. To position a label in the top left of its parent view, constraints are applied that describe the position of the label. The layout engine takes the constraints, transforms them into linear equations, and sets the frames of the elements of the user interface. This approach only works if the constraints eliminate any ambiguity about the position of the label. Under the hood, the label is positioned by setting its frame.

Auto Layout describes the position of a user interface element, regardless of the device model or orientation. The layout engine inspects the constraints and lays out the user interface.

This tutorial teaches you the basics of Auto Layout. You learn how to define constraints in Interface Builder and resolve issues. Let us get started with a simple project in Xcode.

Read this article on Cocoacasts.

autolayoutfundamentals-basics's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.