0% found this document useful (0 votes)
2K views61 pages

Learning iOS UI Development Implement Complex iOS User Interfaces With Ease Using Swift 1st Edition D'Areglia Ebook All Chapters PDF

iOS

Uploaded by

foldyglockpz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views61 pages

Learning iOS UI Development Implement Complex iOS User Interfaces With Ease Using Swift 1st Edition D'Areglia Ebook All Chapters PDF

iOS

Uploaded by

foldyglockpz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Visit https://ebookfinal.

com to download the full version and


explore more ebook

Learning iOS UI Development Implement complex iOS


user interfaces with ease using Swift 1st Edition
D'Areglia

_____ Click the link below to download _____


https://ebookfinal.com/download/learning-ios-ui-
development-implement-complex-ios-user-interfaces-with-
ease-using-swift-1st-edition-dareglia/

Explore and download more ebook at ebookfinal.com


Here are some recommended products that might interest you.
You can download now and explore!

Test Driven IOS Development with Swift 4 Third Edition


Dominik Hauser

https://ebookfinal.com/download/test-driven-ios-development-with-
swift-4-third-edition-dominik-hauser/

ebookfinal.com

iOS 8 Swift Programming Cookbook Solutions Examples for


iOS Apps 1st Edition Nahavandipoor

https://ebookfinal.com/download/ios-8-swift-programming-cookbook-
solutions-examples-for-ios-apps-1st-edition-nahavandipoor/

ebookfinal.com

Learning Swift Building Apps for macOS iOS and Beyond 3rd
Edition Jonathon Manning

https://ebookfinal.com/download/learning-swift-building-apps-for-
macos-ios-and-beyond-3rd-edition-jonathon-manning/

ebookfinal.com

Beginning iOS 7 Development Exploring the iOS SDK 1st


Edition Jack Nutting

https://ebookfinal.com/download/beginning-ios-7-development-exploring-
the-ios-sdk-1st-edition-jack-nutting/

ebookfinal.com
Core Data by Tutorials iOS 8 and Swift Edition Aaron
Douglas

https://ebookfinal.com/download/core-data-by-tutorials-ios-8-and-
swift-edition-aaron-douglas/

ebookfinal.com

Test Driven iOS Development 1st Edition Graham Lee

https://ebookfinal.com/download/test-driven-ios-development-1st-
edition-graham-lee/

ebookfinal.com

Beginning iOS 5 Application Development 1st Edition Wei-


Meng Lee

https://ebookfinal.com/download/beginning-ios-5-application-
development-1st-edition-wei-meng-lee/

ebookfinal.com

Learn Sprite Kit for iOS Game Development 1st Edition


Leland Long

https://ebookfinal.com/download/learn-sprite-kit-for-ios-game-
development-1st-edition-leland-long/

ebookfinal.com

Innovative Lean Development How to Create Implement and


Maintain a Learning Culture Using Fast Learning Cycles 1st
Edition Timothy Schipper
https://ebookfinal.com/download/innovative-lean-development-how-to-
create-implement-and-maintain-a-learning-culture-using-fast-learning-
cycles-1st-edition-timothy-schipper/
ebookfinal.com
Learning iOS UI Development Implement complex iOS
user interfaces with ease using Swift 1st Edition D'Areglia
Digital Instant Download
Author(s): D'areglia, Yari
ISBN(s): 9781785288197, 1785288199
Edition: 1
File Details: PDF, 2.96 MB
Year: 2015
Language: english
Learning iOS UI Development

Implement complex iOS user interfaces with ease


using Swift

Yari D'areglia

BIRMINGHAM - MUMBAI
Learning iOS UI Development

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: December 2015

Production reference: 1181215

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78528-819-7
www.packtpub.com
Credits

Author Project Coordinator


Yari D'areglia Judie Jose

Reviewers Proofreader
Nicola Armellini Safis Editing
Christian Stehno
Indexer
Commissioning Editor Monica Ajmera Mehta
Nadeem N. Bagban
Graphics
Acquisition Editor Jason Monteiro
Manish Nainani
Production Coordinator
Content Development Editor Nilesh Mohite
Rashmi Suvarna
Cover Work
Technical Editor Nilesh Mohite
Humera Shaikh

Copy Editor
Shruti Iyer
About the Author

Yari D'areglia is a developer with 15 years of experience in software architecture


and development. During the last 4 years, he built successful iOS and OS X
applications for developers as well as the mainstream public.

Yari, together with Nicola Armellini, founded Jumpzero, a company based in Italy
that released countless mobile, desktop, and web applications.

Currently, he is employed as a senior iOS engineer at Neato Robotics, a company


based in Silicon Valley, where he works on the communication between robots and
iOS devices.

Yari writes at www.ThinkAndBuild.it, a blog focused on iOS development with a


strong focus on user interface development.

You can reach him on Twitter at @bitwaker.

I'd like to thank Nicola Armellini for taking the time to review this
book and teaching me countless things about my work and life.
Thanks, brother!
Special thanks go to my future wife, Lorena. She was extremely
supportive and accepted all my "I'm busy, honey; I need to finish this
chapter..." with a gentle smile. You are awesome; I love you.
Thanks, mom, your ragù and your words were both of vital
importance during the writing of the last few chapters. You're a
strong woman, and I'm proud to be your son.
Many thanks and appreciation go to everyone who contributed to
the production of this book: Manish, Ritika, Rashmi, and Humera.
Thank you for being so kind and professional.
Last but not least, I would like to thank my greatest friends, Simo,
Luke, and Stefano (Panzer). Our next role-playing session is on its way.
About the Reviewers

Nicola Armellini is a designer from Italy who constantly crosses the boundary
between technology and communication.

First approaching the industry through the video game medium, he partnered
with Yari D'Areglia and founded Jumpzero, specializing in the user experience
and interface design of OS X and iOS applications. At the same time, Nicola helped
grow the audience of Yari's Think & Build blog by editing and reviewing his in-depth
tutorial articles.

A fan of redistributing knowledge and making it accessible, he taught his craft and
its implications in terms of marketing and communication as a lecturer at European
Institute of Design in Milan.

As a side project slowly turned into his main focus, Nicola started fiddling with virtual
reality and exploring new ways of interacting with machines and CG environments,
questioning the status quo of how information is presented and manipulated.

He now studies to become an aerospace engineer and can be found at


nicolaarmellini.com.

Christian Stehno studied computer science and got his diploma from the
University of Oldenburg in 2000. Since then, he has worked on different topics in
computer science. As researcher on theoretical computer science at University,
Christian switched to embedded system design at a research institute later on. In
2010, he started his own company, CoSynth, which develops embedded systems and
intelligent cameras for industrial automation. In addition, Christian is a long-time
member of the Irrlicht 3D Engine developer team.
www.PacktPub.com

Support files, eBooks, discount offers, and more


For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
To my father, Max.
Table of Contents
Preface vii
Chapter 1: UI Fundamentals 1
Exploring windows 1
The contents of windows 2
Configuring windows 2
Working with views 5
Defining the view's geometry 6
The bounds property 7
The frame property 7
The center property 8
UI hierarchy and views inheritance 8
Managing with the hierarchy 9
View and subview visibility 11
Hierarchy events 11
Notes about debug 13
Hands-on code 13
View drawing and life cycle 15
View controllers and views 16
Summary 18
Chapter 2: UI Components Overview – UIKit 19
Exploring text elements 19
Presenting text with UILabel 20
Receiving user input with UITextField 21
Multiline text with UITextView 23
Notes about the keyboard 25
Keyboard events 26
Keyboard configuration 26
Exploring buttons and selectors 27
UIButton and user interaction 27

[i]
Table of Contents

The target-action pattern 28


Boolean selection with UISwitch 29
Control customization 29
Selecting values with UISlider 30
Control customization 30
User choices through UISegmentedControl 31
Control customization 31
Selecting values with UIPickerView and UIDatePicker 33
Updating values with UIStepper 35
Control customization 36
View-based components 36
Showing progress with UIProgressView 36
Control customization 36
Working with UIActivityIndicatorView 37
Control customization 37
Introducing UIImageView and UIImage 37
Introducing UIScrollView 39
Managing and presenting structured data 41
Introducing UITableView 41
Introducing UICollectionView 43
The UIAppearance protocol 44
Hands-on code 45
Summary 46
Chapter 3: Interface Builder, XIB, and Storyboard 47
Interface Builder 47
An overview of the editor 48
Working with XIB files 49
Managing user interfaces with Storyboards 51
Connecting user interfaces with your code 51
Implementing navigation with Storyboard and segues 53
The unwind segue 55
Hands-on code 56
Summary 59
Chapter 4: Auto Layout 61
How Auto Layout works 61
Xcode and Auto Layout 62
Practical introduction to constraints 65
Xcode helpers 68
Intrinsic content size 70
Independence from screen size 72
Updating constraints programmatically 74

[ ii ]
Table of Contents

Working with Auto Layout programmatically 77


Initializing the views 77
Adding constraints 78
Working with multiple views 80
Relations between views 82
Summary 83
Chapter 5: Adaptive User Interfaces 85
UI definition with size classes 85
User interface's traits 87
Trait collection and trait environment 87
Working with trait collections 89
Size classes and Interface Builder 92
Hands-on code 92
Image assets and size classes 96
Working with Dynamic Type 97
Configurable text size 97
Exploring text styles 98
Improving Auto Layout structures with UIStackView 102
Setting up UIStackView 102
UIStackView and adaptive layouts 105
Summary 106
Chapter 6: Layers and Core Animation 107
Exploring layers 107
Layers and views 107
The content of a layer 108
Flat layer 108
The contents property 109
The layer delegate 109
Layer subclassing 110
Contents properties 111
The layer geometry 112
The layers hierarchy 114
The appearance of layers 115
Working with core animation 116
Layers and animations 116
Implicit animations 117
Properties animations 117
Initializing and launching the animation 118
Keeping the animation result 119
Handling timing and repetitions 120
Animations group 122
Keyframe animations 123

[ iii ]
Table of Contents

Removing animations from a layer 124


View animations 125
Summary 126
Chapter 7: UI Interactions – Touches and Gestures 127
Events and touches 127
Touch phases 128
The UITouch class 129
Responder chain 130
Hit-testing 130
Responding to touch events 131
Gestures and gesture recognizers 133
Working with gesture recognizers 134
Gesture recognizer states 135
Hands-on code 136
Summary 137
Chapter 8: How to Build Custom Controls 139
The Thermostat control 139
Designing a custom control 140
The UIControl class 141
Implementing the ThermostatSlider control 142
Control initialization 143
Drawing the control 143
Prototyping using playground 144
Drawing the borders 145
Drawing the track 146
Drawing the handle 146
Updating the control value 147
Updating borders 148
Updating the track 148
Updating the handle 150
Touch tracking 150
Beginning tracking 151
Continuing tracking 152
Ending tracking 152
Sending actions 153
Customizing the control with UI Appearance 154
Summary 154
Chapter 9: Introduction to Core Graphics 155
Drawing on the graphic context 155
How drawing works 156
Handling the graphic states 157
The coordinate system 157

[ iv ]
Table of Contents

UIKit helpers 158


Drawing with fill and stroke options 158
Drawing with blending modes 159
Drawing with paths 159
Drawing with paths 161
Path initialization 161
Building a path 162
Drawing the path 164
Summary 165
Index 167

[v]
Preface
Through this comprehensive one-stop guide, you'll get to grips with the entire UIKit
framework and creating modern user interfaces for your iOS devices using Swift.
Starting with an overview of the iOS drawing system and available tools, you will
learn how to use these technologies to create adaptable layouts and custom elements
for your applications. You'll then be introduced to other topics such as animation
and code drawing with core graphics, which will give you all the knowledge you
need to create astonishing user interfaces. By the time you reach the end of this book,
you will have a solid foundation in iOS user interface development and have gained
a valuable insight into the process of building firm and complex UIs.

What this book covers


Chapter 1, UI Fundamentals, starts by describing how interfaces are structured and
drawn and then presents some really important elements, such as windows and views.

Chapter 2, UI Components Overview – UIKit, is an overview of the UIKit framework.


It's a guided tour through the main UIKit elements, from their usage inside an app to
their customization.

Chapter 3, Interface Builder, XIB, and Storyboard, gives an overview of the Xcode tools
used to set up and build UIs.

Chapter 4, Auto Layout, is the key to understanding how Auto Layout works. It
describes in detail how to create dynamic layouts.

Chapter 5, Adaptive User Interfaces, discusses a very important topic: how to improve
user experience and provide interfaces that can adapt to different orientations, screen
sizes, and user preferences using the latest advancements introduced with iOS 8 and 9.

[ vii ]
Preface

Chapter 6, Layers and Core Animation, focuses on CALayer in the context of


core animation. It illustrates how to achieve animations in iOS using two
different approaches.

Chapter 7, UI Interactions – Touches and Gestures, analyzes the main way users
interact with UIs—through touch. It answers questions such as "how is this
information passed from the screen to the views?" and "how can we build an
engaging UI using gestures?"

Chapter 8, How to Build Custom Controls, explains how to build custom controls after
learning how these controls work in the previous chapters.

Chapter 9, Introduction to Core Graphics, is a final quick overview of the core graphics
(Quartz 2D) framework to show you how to perform custom drawings with iOS.

What you need for this book


In order to be able to run the code examples, you need a Mac computer with OS X
and Xcode installed. The suggested minimal version is OS X 10.11.1 and Xcode 7.1.

Who this book is for


This easy-to-follow guide is perfect for beginner-level iOS developers who want to
become proficient in user interface development. It is also useful for experienced
iOS developers who need a complete overview of this broad topic all in one place
without having to consult various sources.

Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.

Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"The properties that define the view geometry are frame, bounds, and center and
they are configured using the geometry structures you just saw."

[ viii ]
Preface

A block of code is set as follows:


// Define a point
let point = CGPoint(x: 20, y: 10)

// Define a size
let size = CGSize(width: 20, height: 10)

// Define a rect using size and point


let rect_A = CGRect(origin: point, size: size)

// Define a rect using x, y, width and height data


let rect_B = CGRect(x: 15, y: 10, width: 100, height: 30)

When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
enum UIUserInterfaceSizeClass : Int {
case Unspecified
case Compact
case Regular
}

New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: "Create a
new asset by clicking on the + symbol and selecting New Image Asset."

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention


the book's title in the subject of your message.

[ ix ]
Preface

If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.

Downloading the example code


You can download the example code files from your account at http://www.
packtpub.com for all the Packt Publishing books you have purchased. If you
purchased this book elsewhere, you can visit http://www.packtpub.com/support
and register to have the files e-mailed directly to you.

Downloading the color images of this book


We also provide you with a PDF file that has color images of the screenshots/diagrams
used in this book. The color images will help you better understand the changes in
the output. You can download this file from https://www.packtpub.com/sites/
default/files/downloads/LearningiOSUIDevelopment_Graphics.pdf.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/


content/support and enter the name of the book in the search field. The required
information will appear under the Errata section.

[x]
Preface

Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.

Please contact us at [email protected] with a link to the suspected


pirated material.

We appreciate your help in protecting our authors and our ability to bring you
valuable content.

Questions
If you have a problem with any aspect of this book, you can contact us at
[email protected], and we will do our best to address the problem.

[ xi ]
UI Fundamentals
Creating a successful application is not only a matter of writing efficient and reliable
code. User interfaces and experience are relevant topics that we have to seriously
take into account during the development process. If you want to be able to create
appealing and well-structured layouts, you need to become familiar with the main
building blocks of user interfaces.

In this chapter, we will explore the basics of iOS UI development, which you will use
and improve upon for the rest of the book and, hopefully, for the rest of your career.

We will start from the fundamental actors of a user interface, such as windows and
views; then, we will connect the dots showing how all these components work together
by creating a UI hierarchy and how the system interacts with all these elements.

Let's start our journey from the element at the top of the stack: the window.

Exploring windows
A window is an instance of the UIWindow class, and it is the topmost element of any
application UI's hierarchy. It doesn't draw any visual object and can be considered as
a blank container for the UI elements called views. An application must have at least
one window that normally fills the entire screen.

One of the main roles of the window is to deliver touches to the underlying views. You'll
read more about this topic in Chapter 7, UI Interactions – Touches and Gestures. For now,
it suffices to say that a window is the first entry point for a touch event. The touch is
then pushed down through the view hierarchy until it reaches the right view.

[1]
UI Fundamentals

The contents of windows


The contents of your applications are mainly directed by view controllers and
presented through views, which, in turn, are displayed inside a window. As you will
learn in the next section, this sequence is automatically handled by iOS, and all the
classes involved in the process are organized to interact seamlessly.

The easiest and most reliable way to send content to a window is by configuring
its rootViewController property with a UIViewController instance. The view
controller's view will automatically be set as the contents of the window and
presented to the user.

This solution simplifies the window hierarchy, ensuring that contents are all children
of the same root. Thanks to this solution, changing the contents of a window is just a
matter of updating its root view controller.

While you'll learn more about view controllers and views in the next paragraphs,
this image should clarify how all these objects cooperate to present their contents to
the user:

WINDOW VIEW CONTROLLER

rootViewController

view

The view controller is initialized and set as the root view controller of the window.
Finally, the window presents the current root view controller's view.

Configuring windows
You rarely need to set up a window manually. In most cases, Xcode defines all
the needed information for you. Let's take a look at the entire process to better
understand what goes on under the hood.

[2]
Chapter 1

When you create a new Xcode project using the wizard, a Storyboard is created
for you. If you check the info.plist file, you'll see that the Main storyboard
filebase name key reports the name of the Storyboard by default as Main:

This key is really important as it tells Xcode that you want to start the application
from the Storyboard or, more precisely, from the Storyboard initial view controller
(the one indicated by the grey arrow inside the Storyboard working area).

The @UIApplicationMain attribute in the AppDelegate.swift file is responsible


for the launch of the entire application process. It marks an entry point for the
application launch, reading the Storyboard's information from the info.plist file
and instantiating the initial view controller.

At this point, a UIWindow instance is created and associated with the window
property of the AppDelegate class. This property will be a handy reference to the
main window for the entire life cycle of the application.

The initial view controller, previously initialized, is now assigned to the


rootViewController property of the window; therefore, the initial view controller's
view becomes the current window's content.

Since windows are invisible by default, there is one last step required to show the
content to the user. After the application:didFinishLaunchingWithOptions
function finishes its execution, makeKeyAndVisible is called for the window, which
now loads its interface from rootViewController and finally displays it contents.

The following image summarizes all these steps:

@UIApplicationMain
Info.plist

RUST

App Delegate
Main Storyboard

Initial rootViewController
.window
view controller

AFTER makeKeyAndVisible()
applicationDidFinishLaunching:withOptions:

[3]
UI Fundamentals

The same result can be obtained programmatically. If you remove the Main
storyboard filebase name key from the info.plist file, Xcode doesn't have any
information on how to set up a valid window. The application:didiFinishLau
nchingWithOptions function is the right place to manually instantiate it. You can
execute the following:
func application(application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: [NSObject: AnyObject]?) -> Bool {

// Instantiate a window with the same size of the screen


window = UIWindow(frame: UIScreen.mainScreen().bounds)
// Instantiate a view controller with the Main storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController
WithIdentifier("viewController2") as! ViewController

// Setup and present the window


window?.rootViewController = viewController
window?.makeKeyAndVisible()

return true
}

As you can note, this code retraces the same steps that we saw previously. The only
noteworthy thing is the way the window frame is defined: UIScreen is a class that
represents a screen device. In the previous block of code, the mainScreen function
is used to get the current device bounds and build a window that is the same size as
the screen.

Downloading the example code


You can download the example code files for all
Packt books you have purchased from your account
at http://www.packtpub.com. If you purchased
this book elsewhere, you can visit http://www.
packtpub.com/support and register to have the
files e-mailed directly to you.

[4]
Chapter 1

Working with views


Along your path of UI enlightenment, you'll encounter different types of views. You
can simplify the categorization by thinking about a view as the atomic element of the
user interface, where a view has its own specific properties and can be grouped with
other views to create complex hierarchies.

UIView is the base class used to instantiate generic views and it can be subclassed
to create custom views. Almost all the UI elements that you will use in your
applications are inherited from this class, and in the next chapter, you'll learn a lot
about some of the elements provided by Apple within the UIKit framework.

Keep in mind that the UIWindow class too is a subclass


of UIView. This is generally a cause of confusion
considering that in a UI hierarchy, views are the children
of a window and not the other way around.

A UIView instance has properties that you can use to change an aspect of the view.
For example, the backgroundColor property accepts UIColor to define a tint for the
view's background. The background of a view is transparent by default, and as you'll
see later in this chapter, some views can seep through other views.

The alpha property is useful if your view and all the elements it contains need to
be transparent. It accepts a value from 0.0 to 1.0, and depending on your settings,
it gives the view a "see-through" effect. With the help of this property, you can hide
or unhide a view using some interesting animations, as you will learn in Chapter 6,
Layers and Core Animation.

Another way to change the visibility of a view is using the hidden property, which
can be set to true or false.

It's important to note that when you hide a view using the hidden or alpha
properties, you are not removing the view from the hierarchy and memory; the
view can, in fact, still be reached, but the interaction with the user is automatically
disabled until the view is visible again. This is a neat trick to temporarily remove a
view from the screen, thus preventing any unintended interaction.

Sometimes, you might need to disable a view even if the drawing goes on (for
example, you may want to be sure that the UI interactions are disabled while loading
some external data). In this case, you may find the userInteractionEnabled
property useful; setting this property to false tells the view to ignore user events.

[5]
UI Fundamentals

Defining the view's geometry


The properties of some view's have only one role: defining how the view is drawn on
screen. Before diving into a description of these properties, it's worth introducing the
structures that are involved in the definition of the view geometry:

• CGPoint: This is defined by two properties, x and y, and it represents


a single point
• CGSize: This is defined by two properties, width and height, and it
represents a generic size
• CGRect: This is defined by two properties, origin (CGPoint) and size
(CGSize), and it represents a quadrilateral area

When working with iOS, you will encounter different coordinate


systems. With UIViews, the origin of the coordinate system (x:0,
y:0) is on the upper-left side. The x value increases from left to
right, and the y value increases from top to bottom.

The code needed to initialize these structures is straightforward, and there are a lot
of functionalities provided by Apple that simplify our work with these structures.

The following code shows how to create the Rect, Size, and Point instances:
// Define a point
let point = CGPoint(x: 20, y: 10)

// Define a size
let size = CGSize(width: 20, height: 10)

// Define a rect using size and point


let rect_A = CGRect(origin: point, size: size)

// Define a rect using x, y, width and height data


let rect_B = CGRect(x: 15, y: 10, width: 100, height: 30)

The properties that define the view geometry are frame, bounds, and center and
they are configured using the geometry structures you just saw.

[6]
Chapter 1

The bounds property


Let's start with the bounds property. It is a CGRect property that defines information
(size and origin) locally to the view. This means that when we speak about bounds,
we do not determine how the view is drawn in the UI hierarchy but how it's drawn
in a decontextualized, local space. You'll read more about UI hierarchy later in this
chapter; for now, just think about it as a structure that organizes trees of views, where
a view can be either the child or parent of another view. That said, in most cases, the
origin bound is (x:0, y:0), while the size property is the size of the view.

The frame property


On the other hand, the frame property defines how a view is placed inside the
hierarchy. It's a CGRect property similar to bounds, but its origin value determines
how the view is placed inside its parent view.

At this point, we might conclude that frame and bounds are similar; however, this is
not always true. Take a look at the following images to better understand how they
work together to define the view geometry:

In this case, frame and bounds have the same size, but the position values are
different. Take a look at this image:

This indicates that after a rotation, the same view maintains the bounds, while the
frame changes significantly, adapting its size in order to contain the rotated view.

[7]
UI Fundamentals

The center property


The center property works in relation to the UI hierarchy (as does the frame),
and it's a handy way to define the view's position inside its parent. It differs from
frame.origin in the way its position is calculated. With frame, the origin position is
calculated using the upper-left corner of the view, while for the center, the anchor is
the view's center, as you can see from the following image:

UI hierarchy and views inheritance


In this chapter, we already talked about UI hierarchies. Let's dive into the topic by
introducing the concepts of subview and superview and learning how to build and
manage complex hierarchies.

Every instance of UIView (or its subclass) can be connected with other views in a
parent-child relationship. The parent view is called superview, while the children
are called subviews. A view can only have one superview, but it can contain more
than one subview:

[8]
Chapter 1

Thanks to the dedicated UIView properties and functions, you can easily inspect
a view hierarchy and navigate from a root view down through to the last view of
the hierarchy.

A view can access its parent from the superview property, as follows:
let parentView = view.superview

The property returns a single UIView reference or nil if the view is not added to the
hierarchy yet.

In a similar way, the subviews property returns an array of UIView instances that are
the children of the view. Take a look at this code:
let children = view.subviews

Managing with the hierarchy


The UIView class offers helpful functions to add, move, and delete elements from the
hierarchy; you can call these functions directly from the view instances.

The addSubview: function pushes a view as the child of the caller, as follows:
containerView.addSubview(childView)

Views that are added as subviews of the same view are sibling. Sibling subviews are
assigned to an index based on the order of insertion, which in turn corresponds to the
drawing order—the highest index is drawn at the front, while the lowest is drawn
behind the other sibling views. The addSubview: function assigns the first free index
to the view, determining its position, which is in front of all the other views with
lower indexes.

[9]
UI Fundamentals

This order can be manipulated using functions that specify the desired index in an
absolute or relative way:
containerView.insertSubview(childView, atIndex: 2)

With the insertSubview:atIndex function, you can specify an index in which to


place the view. If the index is not free, the view at this index gets shifted up by one
index, consequently shifting all the other sibling views with indexes greater than the
requested one.

With the same logic, a view can be placed into the hierarchy using another
view as a reference and specifying that the new view should be inserted above
(insertSubview:aboveSubview) or below (insertSubview:belowSubview) the
referenced view, as follows:
containerView.insertSubview(childView, aboveSubview: anotherView)

containerView.insertSubview(childView, belowSubview: anotherView)

Removing a view from the hierarchy is extremely simple. If you have a reference
of the view that you want to remove, just call the removeFromSuperview function
for this view. Alternatively, if you want to remove all the subviews from the parent
view, just loop through the subviews and remove the views one by one. You can use
the following code for this:
for subview in container.subviews {
subview.removeFromSuperview()
}

When you remove a view from the hierarchy, you are removing
its subviews as well. If you haven't defined any reference to
the views, they are no longer retained in memory; therefore, all
chances to get access to the views are lost.

When you need to access a subview on the fly without saving a reference to it,
you can use the tag property. A UIView instance can be easily marked using an
integer, and you can obtain the view that corresponds to the same tag using the
viewWithTag; function. This function returns the view itself or the first subview
whose tag coincides with the requested tag.

[ 10 ]
Chapter 1

View and subview visibility


A parent view defines its subviews' visibility outside its boundaries through the
Boolean property clipToBounds. If this property is true, the view behaves as a
mask for its subviews, preventing them from being drawn outside the boundaries.
The following image presents the result of different clipToBounds values on the
same hierarchy:

Another important note about subview visibility is related to the alpha property,
which, as we mentioned previously, defines the opacity of the view. Subviews
indirectly inherit the alpha value from their superviews, so the resulting opacity of
the subview depends both on their parent and their own alpha.

If your view has a nontransparent background, it is good


practice to leave the opaque property set to true as a hint
for the drawing system. Opaque views are optimized for
this. The opposite is suggested if the view is fully or partially
transparent; set this property to false.

Hierarchy events
Changes on the hierarchy can be intercepted and managed through callbacks called
on the parent and child views.

[ 11 ]
UI Fundamentals

When a view is attached to a superview, the didMoveToSuperview function is called.


If we want to perform a task after this event is triggered, we have to override this
function with a UIView subclass by executing the following code:
class CustomView: UIView {

override func didMoveToSuperview() {


println("I have a superview!")
}
}

In the same way, the event can be intercepted by the superview overriding the
didAddSubview:subview function, as follows:

override func didAddSubview(subview: UIView) {


println("The subview \(subview) has been added")
}

The view will be added to a hierarchy that has a window as root. At this point, the
didMoveToWindow event is called. After the event is triggered, the window property
of the view instance becomes a reference to the root window; this turns out to be a
handy way to check whether a view has reached the screen.

Remember that the only way to show a view on screen is through a window; so, if
the window property is nil, you can be sure that the view is not added to a window
hierarchy yet and that, for this reason, it won't be visible. Take a look at this code:
override func didMoveToWindow() {
println("I've been attached to this window hierarchy: \(window)")
}

Another important method that responds to hierarchy changes is layoutSubviews.


This function is called as soon as a subview is added to or removed from the
hierarchy and every time the bounds of the view change. Within this function,
Auto Layout constraints (more on this will be discussed in Chapter 5, Adaptive User
Interfaces) are read, and they act to organize the subview's layout. You can override
this function to perform your customizations to the layout, adding or tweaking the
current constraints.

[ 12 ]
Chapter 1

Notes about debug


When views are complex, the hierarchy is hardly straightforward. Xcode helps you,
though, with an interesting debug instrument. When your application is running,
select Debug -> View Debugging -> Capture View Hierarchy from the Xcode
menu, and you'll see an interactive 3D representation of the current view hierarchy
showing the depth and the position of all the views contained:

Hands-on code
In this section, you will practice some of the concepts that we just discussed by
writing a real application.

Open the Chapter 1 folder and launch the ...\Start\Chapter1 project. You'll
find a simple application structure that is the starting point for this exercise; the final
result is the ...\Completed\Chapter1 project.

[ 13 ]
UI Fundamentals

The base structure is really simple: an uppermost area with some controls (two
buttons and one segmented control) and a view (with a light gray background)
that we call a container:

Your goal is to implement the createView: function that receives a location


(CGPoint) and adds a subview at this location inside the container. Depending on
the value of the segmented control, you should use the received location as the
center (red views) or upper-left corner of the new view (blue views). You need to
also implement the clear function to remove all the added subviews. The project
implements a tap gesture on the container, which invokes createView linked to the
touch location.

Let's implement the createView function for the viewController.swift file first by
executing the following:
func createView(location:CGPoint){
let viewSize = CGSize(width: 50, height: 50)
let viewFrame = CGRect(origin: location, size: viewSize)

[ 14 ]
Chapter 1

let childView = UIView(frame: viewFrame)


childView.backgroundColor = UIColor.redColor()
viewContainer.addSubview(childView)

if isCenterAligned {
childView.center = location
childView.backgroundColor = UIColor.blueColor()
}
}

The childView function is instantiated using a fixed size and the received location
as its origin. Then, it is simply attached to viewContainer using addSubview. If the
isCenterAligned property (which is handled by the segmented control) is true, the
center property of the view is moved to the received location.

The implementation of the clear function is straightforward, as you can note in the
following code:
@IBAction func clear(){
for subview in viewContainer.subviews{
subview.removeFromSuperview()
}
}

It just performs a loop through the viewContainer subviews to call the


removeFromSuperview function on these subviews.

A second functionality can be added to this exercise. Push the "Deep" button on the
upper-left side of the screen, and debug the current hierarchy using the "capture
view hierarchy" function to see this great feature in action!

View drawing and life cycle


iOS uses remarkable optimizations in the process of drawing contents on screen.
Views are not continuously drawn; the system draws any view just once and creates
snapshots for each displayed element. The current snapshot is shown until a view
doesn't require an update. The view is then redrawn, and a new snapshot for the
updated view is taken. This is a clever way to avoid a wastage of resources. In
devices such as smartphones, optimization is mandatory.

The UIView content can be invalidated by calling the setNeedsDisplay: or


setNeedsDisplayInRect: function.

[ 15 ]
UI Fundamentals

This call basically tells the drawing system that the view content needs to be
updated with a new version. Later, during the next run loop, the system asks
the view to redraw. The main difference between the setNeedsDisplay: and
setNeedsDisplayInRect: functions is that the latter performs an optimization
using only a portion of the new view content.

In most cases, the redrawing process is managed for you by UIKit. If you need to
create your really custom UIView subclass, though, you probably want to draw
the contents of the view yourself. In this case, the drawRect: function is the place
where you will add the drawing functions. You'll learn more about custom drawing
in Chapters 6, Layers and Core Animation, and Chapter 9, Introduction to Core Graphics.
For now, it suffices to say that you should never call this function directly! When
the content of the view needs to be updated, just call setNeedDisplay: and the
drawRect: function will be executed by the system following the right procedure.

Here is a quick example of custom drawing with which we can create a UIView
subclass that draws a simple red ellipse at the center of the view:
import UIKit

class ellipseView: UIView {

override func drawRect(rect: CGRect) {

let path = UIBezierPath(ovalInRect: self.bounds)


UIColor.redColor().setStroke()
UIColor.orangeColor().setFill()
path.fill()
path.stroke()

}
}

This function uses UIBezierPath to define an oval shape that has a stroke and fill of
red and orange. This shape is finally drawn in the current Graphic Context, which can
be seen as an empty dashboard where you can design using code. You'll learn more
about Graphic Contexts in Chapter 9, Introduction to Core Graphics.

View controllers and views


The UIViewController property view is the root view of the hierarchy that defines
the view controller's contents. As we already saw, a view controller is associated
with the window's rootViewController property, and a connection is established
between the window property of the view controller view and the window.

[ 16 ]
Chapter 1

During its life cycle, a view controller deals with important events related to its view.
Depending on your needs, you might find these events useful for the UI definition.

Here is a quick but complete description of the functions called in relation to


these events:

Function Description
loadView This is called when the view is created and assigned
to the view property. Depending on the setup of
the view controller, a view can be created using a
Storyboard or a .xib file. You will not override
this method unless you decide not to implement the
view using Interface Builder.
viewDidLoad This is called after the view is loaded. You will
override this to perform additional adjustments
to the user interface. You can set the text value
of labels with the data received from a previous
controller in the navigation hierarchy, for instance.
viewWillAppear This is called just before the view is added to
a view hierarchy. It is obviously called after
viewDidLoad, and it may be called more than once
during the view controller's life cycle.
viewDidAppear This is called after the view is added to a view
hierarchy. When this method is called, the view is
visible, and its window property is no longer nil.
viewWillLayoutSubviews This method is called when the view bounds
change or are initialized and the view is about to lay
out the subviews.
viewDidLayoutSubview When this method is called, the bounds are set
and the view has just called the layoutSubviews
method.

The appear-functions are called when the controller is presented for the first time
when a back button is pressed or a modal is closed, showing the underlying view
controller again. If you override these methods, you are required to call them on
super before executing your code.

[ 17 ]
Exploring the Variety of Random
Documents with Different Content
step which still retains some of the stateliness that once
distinguished the Princess Hermengarde.
When the visit is over, the stricken mother returns to her lonely
home, in a distant corner of the kingdom, where she lives under the
name of the Countess Walstadt, and bestows the larger part of her
revenues upon the poor. The only pleasure she permits herself is the
occasional society of Dorothea, who generally brings with her a little
girl named Hermengarde, with flaxen hair and big blue eyes, who
sits on the elder woman’s knee, and shyly accepts her caresses.
Only one name is never mentioned between the two friends, and
Dorothea will never know the entire truth concerning the fate of
Maximilian: whether he was in reality mad; or whether he was only
deemed so by the brief-lived swarm that infests God’s glorious
creation, and re-makes God in its own image, and sets up the
standards of its own blind limitations, and proclaims them to be the
laws of life.
“He has outsoared the shadow of their night—
Envy and calumny and hate and pain.”
THE END.
TRANSCRIBER’S NOTES:
Obvious typographical errors have been corrected.
Inconsistencies in hyphenation have been
standardized.
Archaic or variant spelling has been retained.
*** END OF THE PROJECT GUTENBERG EBOOK A CROWN OF
STRAW ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like