About This eBook
ePUB is an open, industry-standard format for eBooks. However, support of ePUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the eBook in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
iOS Auto Layout Demystified
Second Edition
Erica Sadun
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Cape Town Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
For sales outside the United States, please contact:
International Sales
Visit us on the Web: informit.com/aw
Library of Congress Control Number: 2013948434
Copyright 2014 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
AirPlay, AirPort, AirPrint, AirTunes, App Store, Apple, the Apple logo, Apple TV, Aqua, Bonjour, the Bonjour logo, Cocoa, Cocoa Touch, Cover Flow, Dashcode, Finder, FireWire, iMac, Instruments, Interface Builder, iOS, iPad, iPhone, iPod, iPod touch, iTunes, the iTunes logo, Leopard, Mac, Mac logo, Macintosh, Multi-Touch, Objective-C, Quartz, QuickTime, QuickTime logo, Safari, Snow Leopard, Spotlight, and Xcode are trademarks of Apple, Inc., registered in the United States and other countries. OpenGL and the logo are registered trademarks of Silicon Graphics, Inc. The YouTube logo is a trademark of Google, Inc. Intel, Intel Core, and Xeon are trademarks of Intel Corp. in the United States and other countries.
ISBN-13: 978-0-321-96719-0
ISBN-10: 0-321-96719-4
Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana.
First printing: October 2013
Editor-in-Chief
Mark Taub
Senior Acquisitions Editor
Trina MacDonald
Senior Development Editor
Chris Zahn
Managing Editor
Kristy Hart
Senior Project Editor
Betsy Gratner
Copy Editor
Kitty Wilson
Indexer
Joy Dean Lee
Proofreader
Anne Goebel
Technical Reviewers
Mike Shields
Ashley Ward
Editorial Assistant
Olivia Basegio
Cover Designer
Chuti Prasertsith
Compositor
Nonie Ratcliff
Hop. Hop. THOOM.
Preface
Auto Layout reimagines the way developers create user interfaces. It creates a flexible and powerful system that describes how views and their content relate to each other and to the windows and superviews they occupy. In contrast with older design approaches, this technology offers incredible control over layout, with a wider range of customization than frames, springs, and struts allow. Somewhat maligned by exasperated developers, Auto Layout has gained a reputation for difficulty and frustration, particularly when used through Interface Builder (IB).
Thats why this book exists. Youre about to discover Auto Layout mastery by example, with plenty of explanations and tips. Instead of struggling with class documentation, youll learn in simple steps how the system works and why its far more powerful than you first imagined. Youll read about common design scenarios and discover best practices that make Auto Layout a pleasure rather than a chore to use.
Youll explore many of the strengths of Auto Layout as well. Its a technology that has a lot going for it:
Auto Layout is declarative. You express the interface behavior without worrying about how those rules get implemented. Just describe the layout; let Auto Layout calculate the frames.
Auto Layout is descriptive and relational. You describe how items relate to each other onscreen. Forget about sizes and positions. What matters is the relationships.
Auto Layout is centralized. Whether in IB or a layout section in your own code, Auto Layout rules tend to migrate to a single nexus, making it easier to inspect and debug.
Auto Layout is dynamic. Your interface updates as needed to respond to user- and application-sourced changes.
Auto Layout is localizable. Conquer the world with Auto Layout. Its built to adapt to varying word and phrase lengths while maintaining interface integrity.