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 Drawing
Practical UIKit Solutions
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
Copyright 2014 Pearson Education, Inc.
All rights reserved. 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, Fire-Wire, 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, or OpenGL Logo,: OpenGL is a registered trademark 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-94787-1
ISBN-10: 0-321-94787-8
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
Proofreader
Anne Goebel
Technical Reviewer
Richard Wardell
Editorial Assistant
Olivia Basegio
Cover Designer
Chuti Prasertsith
For my kids. Hang in there, guys! I love you.
Acknowledgments
No book is the work of one person. I want to thank my team, who made this possible. The lovely Trina MacDonald green-lighted this title, so you have the opportunity now to read it. Chris Zahn is my wonderful development editor, and Olivia Basegio makes everything work even when things go wrong.
I send my thanks to the entire Addison-Wesley/Pearson production team, specifically Kristy Hart, Betsy Gratner, Kitty Wilson, Anne Goebel, and Chuti Prasertsith.
Thanks go as well to Stacey Czarnowski, my new agent now that Neil Salkind retired; to Rich Wardwell, my technical editor; and to my colleagues, both present and former, at TUAW and the other blogs Ive worked at.
I am deeply indebted to the wide community of iOS developers who have supported me in IRC and who helped read this book and offer feedback. Particular thanks go to Oliver Drobnik, Aaron Basil (Ethervision), Harsh Trivedi, Michael Prenez-Isbell, Alex Hertzog, Neil Taylor, Maurice Sharp, Rod Strougo, Chris Samuels, Wess Cope, Hamish Allan, Jeremy Tregunna, Mahipal Raythattha, Eddie Kim, Jeremy Sinclair, Jeff Tentschert, Greg Hartstein, Mike Greiner, Ajay Gautam, Shane Zatezalo, Doug Drummond, Wil Macaulay, Mike Kale, Bill DeMuro, Evan Stone, Ashley Ward, Nick Pannuto, Diederik Hoogenboom, Nico Ameghino, Duncan Champney, August Joki, Remy psy Demarest, Joshua Weinburg, Emanuele Vulcano, and Charles Choi. Their techniques, suggestions, and feedback helped make this book possible. If I have overlooked anyone who helped contribute, please accept my apologies for the oversight.
Special thanks also go to my husband and kids. You are wonderful.
About the Author
Erica Sadun is the bestselling author, coauthor, and contributor to several dozen books on programming, digital video and photography, and web design, including the widely popular The Core iOS 6 Developers Cookbook, Fourth Edition. She currently blogs at TUAW.com and has blogged in the past at OReillys Mac Devcenter, Lifehacker, and Ars Technica. In addition to being the author of dozens of iOS-native applications, Erica holds a Ph.D. in computer science from Georgia Techs Graphics, Visualization, and Usability Center. A geek, a programmer, and an author, shes never met a gadget she didnt love. When not writing, she and her geek husband parent three geeks-in-training, who regard their parents with restrained bemusement when theyre not busy rewiring the house or plotting global dominance.
Preface
Apple has lavished iOS with a rich and evolving library of 2D drawing utilities. These APIs include powerful features like transparency, path-based drawing, antialiasing, and more. They offer low-level, lightweight, easy-to-integrate drawing routines that you can harness to build images, to display views, and to print.