Book Image

Swift Essentials

By : Alex Blewitt, Bandlem Limited
Book Image

Swift Essentials

By: Alex Blewitt, Bandlem Limited

Overview of this book

Table of Contents (16 chapters)
Swift Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using Auto Layout


Auto Layout has been part of Xcode for the last few releases, and it was added to support an evolution from the previous springs and struts approach that predated Mac OS X. First released on iOS in 6.0, it has evolved to the point where size-independent displays can now be created as the default.

Understanding constraints

In Xcode 5, interface builder enabled Auto Layout by default for the first time. When a label was dragged to the top or bottom of the parent view, a dotted blue line would indicate that the label was correctly spaced, and a constraint would be generated.

However, in many cases, the constraints weren't created correctly or had undesired effects. For example, positioning a button in the center at the top might not maintain the location depending on whether the constraint being added was absolute (200 px from the right) or relative (in the center of the screen). In both cases, the button might look like it was positioned correctly, only to fail when the device...