Vous êtes sur la page 1sur 23

iOS Lec #12

Auto Layout
Auto Layout is a constraint-based layout
system. It allows developers to create an
adaptive interface that responds to changes in
screen size and device orientation.
constraints
• These constraints express rules for the layout
of label in the interface.
• The constraints, however, are expressed in
mathematical form. For example, if you’re
defining the position of a button, you might
want to say “the left edge should be 30 points
from the left edge of its containing view.
• Here’s some of the common terminology you
will come across when using Interface Builder
• The Pin menu is located on the bottom right
of the editor. This menu is used to add new
constraints to UI elements like buttons and
labels.
• The Align menu is located to left of the Pin
menu at the bottom right of the editor. This
menu creates alignment constraints. You’d use
this menu to vertically align a label relative to
another view.
• The Document Outline is located on the left
side of the editor. This panel is used to view
the hierarchy of a view’s layout. This is useful
when trying to figure out the relationship of a
view.
• The Attributes Inspector is located in the
middle utility pane on the right side of Xcode.
This panel is used to customize a view’s
attributes. You’d use this panel to change the
background color of a view or the text of a
button.
• T-bars are Xcode’s way of visualizing
constraints on a view. In the image below
there are 3 T-bars that represent the button’s
top, leading, and trailing constraints. These
bars will also indicate if there are any
warnings or errors by turning either yellow or
red.
Task
• https://www.raywenderlich.com/443-auto-
layout-tutorial-in-ios-11-getting-started
Delegates and Data Sources
• A delegate is an object that acts on behalf of,
or in coordination with, another object when
that object encounters an event in a program
• The delegating object is often a responder
object that is responding to a user event.
Contt..
• delegation makes it possible for one object to
alter the behavior of another object without
the need to inherit from it.
Data Source
• A data source is almost identical to a delegate.
The difference is in the relationship with the
delegating object. Instead of being delegated
control of the user interface, a data source is
delegated control of data.
The delegating object, typically a view object
such as a table view, holds a reference to its data
source and occasionally asks it for the data it
should display.
Data sources are responsible for managing the
memory of the model objects they give to the
delegating view.
UITableView
Table View is one of the common UI elements in iOS
apps.
Most apps, in some ways, make use of Table View to
display list of data. The best example is the built-in
Phone app. Your contacts are displayed in a Table View.
Strong and Weak References
• Apple uses Automatic Reference Counting,
(ARC) to manage and track memory usage
on an app.
• references are used to describe the
relationship between objects.
Strong
• A strong reference (which you will use in most
cases) means that you want to "own" the
object you are referencing with this
property/variable.
• once you set the property to nil will the object
get destroyed.
• increment the reference count of the object
by 1.
Weak:
• In contrast, with a weak reference you signify
that you don't want to have control over the
object's lifetime. The object you are
referencing weakly only lives on because at
least one other object holds a strong
reference to it.
Lab Task 05
• Auto Layout
• Table View

Vous aimerez peut-être aussi