SlideShare a Scribd company logo
UIKit User Interface Catalog
Contents
Views 13
About Views 14
Configuring Views 16
Setting View Content 16
Specifying View Behavior 17
Customizing View Appearance 18
Using Auto Layout with Views 20
Making Views Accessible 21
Debugging Views 21
Action Sheets 22
Configuring Action Sheets 22
Setting Action Sheet Content Programmatically 22
Specifying Action Sheet Behavior Programmatically 23
Using Auto Layout with Action Sheets 24
Making Action Sheets Accessible 24
Internationalizing Action Sheets 24
Debugging Action Sheets 24
Elements Similar to an Action Sheet 25
Activity Indicators 26
Configuring Activity Indicators 26
Setting Activity Indicator Values 26
Specifying Activity Indicator Behavior 27
Customizing Activity Indicator Appearance 27
Using Auto Layout with Activity Indicators 28
Making Activity Indicators Accessible 28
Internationalizing Activity Indicators 29
Debugging Activity Indicators 29
Elements Similar to an Activity Indicator 29
Alert Views 30
Configuring Alert Views 30
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
2
Setting Alert View Content Programmatically 31
Specifying Alert View Behavior Programmatically 32
Customizing Alert View Appearance 33
Using Auto Layout with Alert Views 33
Making Alert Views Accessible 33
Internationalizing Alert Views 33
Debugging Alert Views 34
Elements Similar to an Alert View 34
Collection Views 35
Configuring Collection Views 36
Setting Collection View Content 36
Specifying Collection View Behavior 37
Customizing Collection View Appearance 39
Using Auto Layout with Collection Views 40
Making Collection Views Accessible 40
Internationalizing Collection Views 41
Elements Similar to a Collection View 41
Image Views 42
Configuring Image Views 43
Setting Image View Content 43
Specifying Image View Behavior 44
Customizing Image View Appearance 44
Using Auto Layout with Image Views 45
Making Image Views Accessible 46
Internationalizing Image Views 46
Debugging Image Views 46
Elements Similar to an Image View 47
Labels 49
Configuring Labels 50
Setting Label Content 51
Specifying Label Behavior 51
Customizing Label Appearance 52
Using Auto Layout with Labels 53
Making Labels Accessible 53
Internationalizing Labels 54
Debugging Labels 54
Elements Similar to a Label 54
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
3
Contents
Navigation Bars 55
Configuring Navigation Bars 56
Setting Navigation Bar Content 56
Specifying Navigation Bar Behavior 57
Customizing Navigation Bar Appearance 58
Using Auto Layout with Navigation Bars 60
Making Navigation Bars Accessible 60
Internationalizing Navigation Bars 60
Debugging Navigation Bars 60
Elements Similar to a Navigation Bar 61
Picker Views 62
Configuring Picker Views 62
Setting Picker View Content Programmatically 62
Specifying Picker View Behavior 63
Customizing Picker View Appearance 63
Using Auto Layout with Picker Views 63
Making Picker Views Accessible 64
Internationalizing Picker Views 64
Debugging Picker Views 64
Elements Similar to a Picker View 64
Progress Views 65
Configuring Progress Views 65
Setting Progress View Value 66
Customizing Progress View Appearance 66
Using Auto Layout with Progress Views 67
Making Progress Views Accessible 68
Internationalizing Progress Views 68
Elements Similar to a Progress View 68
Scroll Views 69
Configuring Scroll Views 70
Setting Scroll View Content 70
Specifying Scroll View Behavior 70
Customizing Scroll View Appearance 73
Using Auto Layout with Scroll Views 74
Making Scroll Views Accessible 74
Internationalizing Scroll Views 74
Elements Similar to a Scroll View 74
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
4
Contents
Search Bars 75
Configuring Search Bars 76
Setting Search Bar Content 77
Specifying Search Bar Behavior 78
Customizing Search Bar Appearance 79
Using Auto Layout with Search Bars 80
Making Search Bars Accessible 81
Internationalizing Search Bars 81
Debugging Navigation Bars 81
Elements Similar to a Search Bar 82
Tab Bars 83
Configuring Tab Bars 83
Specifying Tab Bar Content 84
Specifying Tab Bar Behavior 84
Customizing Tab Bar Appearance 84
Using Auto Layout with Tab Bars 86
Making Tab Bars Accessible 86
Internationalizing Tab Bars 86
Elements Similar to a Tab Bar 87
Table Views 88
Configuring Table Views 91
Setting Table Content 92
Specifying Table View Behavior 93
Customizing Table View Appearance 95
Using Auto Layout with Table Views 97
Making Table Views Accessible 97
Internationalizing Table Views 97
Elements Similar to a Table View 97
Text Views 98
Configuring Text Views 99
Setting Text View Content 99
Specifying Text View Behavior 100
Customizing Text View Appearance 101
Using Auto Layout with Text Views 102
Making Text Views Accessible 102
Internationalizing Text Views 102
Debugging Text Views 102
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
5
Contents
Elements Similar to a Text View 103
Toolbars 104
Configuring Toolbars 105
Setting Toolbar Content 105
Specifying Toolbar Behavior 106
Customizing Toolbar Appearance 107
Using Auto Layout with Toolbars 109
Making Toolbars Accessible 109
Internationalizing Toolbars 110
Debugging Toolbars 110
Elements Similar to a Toolbar 110
Web Views 111
Configuring Web Views 112
Setting Web View Content Programmatically 112
Specifying Web View Behavior 112
Customizing Web View Appearance 113
Using Auto Layout with Web Views 113
Making Web Views Accessible 113
Internationalizing Web Views 113
Debugging Web Views 113
Elements Similar to a Web View 114
Controls 115
About Controls 116
Configuring Controls 117
Setting Control Content 117
Specifying Control Behavior 117
Customizing Control Appearance 119
Using Auto Layout with Controls 120
Making Controls Accessible 121
Buttons 123
Configuring Buttons 124
Setting Button Content 125
Specifying Button Behavior 125
Customizing Button Appearance 126
Using Auto Layout with Buttons 129
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
6
Contents
Making Buttons Accessible 129
Internationalizing Buttons 130
Debugging Buttons 130
Elements Similar to a Button 130
Date Pickers 131
Configuring Date Pickers 132
Setting Date Picker Values 132
Specifying Date Picker Behavior 133
Customizing Date Picker Appearance 134
Using Auto Layout with Date Pickers 134
Making Date Pickers Accessible 135
Internationalizing Date Pickers 135
Debugging Date Pickers 135
Elements Similar to a Date Picker 136
Page Controls 137
Configuring Page Controls 138
Specifying Page Control Values 138
Specifying Page Control Behavior 138
Customizing Page Control Appearance 139
Using Auto Layout with Page Controls 140
Making Page Controls Accessible 140
Internationalizing Text Fields 141
Debugging Page Controls 141
Elements Similar to a Page Control 141
Segmented Controls 142
Configuring Segmented Controls 142
Setting Segmented Control Values 143
Specifying Segmented Control Behavior 143
Customizing Segmented Control Appearance 145
Using Auto Layout with Segmented Controls 147
Making Segmented Controls Accessible 147
Internationalizing Segmented Controls 147
Debugging Segmented Controls 147
Elements Similar to a Segmented Control 148
Sliders 149
Configuring Sliders 150
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
7
Contents
Setting Slider Values 150
Specifying Slider Behavior 151
Customizing Slider Appearance 151
Using Auto Layout with Sliders 153
Making Sliders Accessible 154
Internationalizing Sliders 154
Debugging Sliders 154
Elements Similar to a Slider 155
Steppers 156
Configuring Steppers 156
Setting Stepper Values 157
Specifying Stepper Behavior 157
Customizing Stepper Appearance 158
Using Auto Layout with Steppers 159
Making Steppers Accessible 159
Internationalizing Steppers 160
Elements Similar to a Stepper 160
Switches 161
Configuring Switches 161
Setting Switch Value 162
Specifying Switch Behavior Programmatically 162
Customizing Switch Appearance 162
Using Auto Layout with Switches 163
Making Switches Accessible 163
Internationalizing Switches 164
Debugging Switches 164
Elements Similar to a Switch 164
Text Fields 165
Configuring Text Fields 165
Setting Text Field Content 166
Specifying Text Field Behavior 166
Customizing Text Field Appearance 168
Using Auto Layout with Text Fields 169
Making Text Fields Accessible 169
Internationalizing Text Fields 170
Elements Similar to a Text Field 170
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
8
Contents
Attributes Inspector Reference 171
Activity Indicator View 173
Activity Indicator View Attributes Inspector Reference 173
Appearance and Behavior 173
Bar Button Item 175
Bar Button Item Attributes Inspector Reference 175
Appearance 175
Bar Item 178
Bar Item Attributes Inspector Reference 178
Appearance, Behavior, and Tagging 178
Button 179
Button Attributes Inspector Reference 179
Type 179
Appearance 179
Behavior 182
Edge Insets 184
Collection Reusable View 185
Collection Reusable View Attributes Inspector Reference 185
Cell Reuse 185
Collection View 186
Collection View Attributes Inspector Reference 186
Layout, Scrolling, Header, and Footer 186
Collection View Cell 188
Collection View Cell Attributes Inspector Reference 188
Cell Reuse 188
Control 189
Control Attributes Inspector Reference 189
Layout 189
Behavior 190
Date Picker 191
Date Picker Attributes Inspector Reference 191
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
9
Contents
Functionality 191
Date 192
Count Down Timer 193
Image View 194
Image View Attributes Inspector Reference 194
Images 194
Behavior 194
Label 195
Label Attributes Inspector Reference 195
Text and Behavior 195
Text Baseline and Line Breaks 197
Text Sizing 198
Text Highlight and Shadow 199
Navigation Bar 200
Navigation Bar Attributes Inspector Reference 200
Appearance 200
Navigation Item 201
Navigation Item Attributes Inspector Reference 201
PropertyGroup 201
Page Control 202
Page Control Attributes Inspector Reference 202
Behavior and Pages 202
Appearance 203
Picker View 204
Picker View Attributes Inspector Reference 204
Behavior 204
Progress View 205
Progress View Attributes Inspector Reference 205
Appearance and Progress 205
Scroll View 206
Scroll View Attributes Inspector Reference 206
Appearance 206
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
10
Contents
Scroll Indicators and Scrolling 206
Scroll Bounce 208
Zooming 209
Events and Zoom Bounce 209
Search Bar 211
Search Bar Attributes Inspector Reference 211
Search Term and Captions 211
Appearance 211
Capabilities 212
Scope Titles 213
Text Input 213
Segmented Control 215
Segmented Control Attributes Inspector Reference 215
Appearance and Behavior 215
Segment Appearance and Behavior 216
Slider 218
Slider Attributes Inspector Reference 218
Value 218
Images 218
Appearance 219
Update Events 219
Stepper 220
Stepper Attributes Inspector Reference 220
Value 220
Behavior 220
Switch 222
Switch Attributes Inspector Reference 222
Appearance and State 222
Tab Bar 223
Tab Bar Attributes Inspector Reference 223
Appearance 223
Tab Bar Item 224
Tab Bar Item Attributes Inspector Reference 224
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
11
Contents
Appearance 224
Table View 225
Table View Attributes Inspector Reference 225
Appearance 225
Behavior 226
Table Index 226
Table View Cell 227
Table View Cell Attributes Inspector Reference 227
Style 227
Cell Reuse 227
Appearance 228
Indentation and Behavior 229
Text View 231
Text View Attributes Inspector Reference 231
Text 231
Behavior 233
Data Detection 233
Text Input and Keyboard 234
Toolbar 238
Toolbar Attributes Inspector Reference 238
Appearance 238
View 239
View Attributes Inspector Reference 239
Layout and Tagging 239
Events 240
Appearance 240
Drawing and Sizing 241
Sizing 242
Web View 243
Web View Attributes Inspector 243
Scaling 243
Detection 243
Document Revision History 245
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
12
Contents
● “About Views” (page 14)
● “Action Sheets” (page 22)
● “Activity Indicators” (page 26)
● “Alert Views” (page 30)
● “Collection Views” (page 35)
● “Image Views” (page 42)
● “Labels” (page 49)
● “Navigation Bars” (page 55)
● “Picker Views” (page 62)
● “Progress Views” (page 65)
● “Scroll Views” (page 69)
● “Search Bars” (page 75)
● “Tab Bars” (page 83)
● “Table Views” (page 88)
● “Text Views” (page 98)
● “Toolbars” (page 104)
● “Web Views” (page 111)
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
13
Views
Important: This is a preliminary document for an API or technology in development. Although this document
has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only
by registered members of the applicable Apple Developer program. Apple is supplying this confidential
information to help you plan for the adoption of the technologies and programming interfaces described
herein. This information is subject to change, and software implemented according to this document should
be tested with final operating system software and final documentation. Newer versions of this document
may be provided with future seeds of the API or technology.
You can think of views as building blocks that you use to construct your user interface. Rather than use one
view to present all of your content, you often use several views to build a view hierarchy. These views range
from simple buttons and text labels to more complex views such as table views, picker views, and scroll views.
Each view in the hierarchy presents a particular portion of your user interface and is generally optimized for a
specific type of content.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
14
About Views
All views in UIKit are subclasses of the base class UIView. For example, UIKit has views specifically for presenting
images, text, and other types of content. In places where the predefined views do not provide what you need,
you can also define custom views and manage the drawing and event handling yourself.
Views allow the user to:
● Experience app content
● Navigate within an app
Implementation: Views are implemented in the UIView class and discussed in UIView Class Reference.
About Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
15
Configuring Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting View Content
Use the Mode (contentMode) field to specify how a view lays out its content when its bounds change. This
property is often used to implement resizable controls. Instead of redrawing the contents of the view every
time its bounds change, you can use this property to specify that you want to scale the contents or pin them
to a particular spot on the view.
The Tag (tag) field serves as an integer that you can use to identify view objects in your app.
About Views
Configuring Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
16
Specifying View Behavior
By default, the User Interaction Enabled (userInteractionEnabled) checkbox is selected, which means
that user events—such as touch and keyboard—are delivered to the view normally. When the checkbox is
unselected, events intended for the view are ignored and removed from the event queue.
The Multiple Touch (multipleTouchEnabled) checkbox is unselected by default, which means that the view
receives only the first touch event in a multi-touch sequence. When selected, the view receives all touches
associated with a multitouch sequence.
Views have a number of properties related to drawing behavior:
● The Opaque (opaque) checkbox tells the drawing system how it should treat the view. If selected, the
drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing
operations and improve performance. If unselected, the drawing system composites the view normally
with other content. You should always disable this checkbox if your view is fully or partially transparent.
● If the Hidden (hidden) checkbox is selected, the view disappears from its window and does not receive
input events.
● When the Clears Graphics Context (clearsContextBeforeDrawing) checkbox is selected, the drawing
buffer is automatically cleared to transparent black before the view is drawn. This behavior ensures that
there are no visual artifacts left over when the view’s contents are redrawn.
● Selecting the Clip Subviews (clipsToBounds) checkbox causes subviews to be clipped to the bounds of
the view. If unselected, subviews whose frames extend beyond the visible bounds of the view are not
clipped.
● When the Autoresize Subviews (autoresizesSubviews) checkbox is selected, the view adjusts the size
of its subviews when its bounds change.
About Views
Configuring Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
17
Customizing View Appearance
Setting View Background Color and Alpha
Adjusting the Alpha (alpha) field changes the transparency of the view as a whole. This value can range from
0.0 (transparent) to 1.0 (opaque). Setting a view’s alpha value does not have an effect on embedded subviews.
Use the Background (backgroundColor) field to select a color to fill in the entire frame of the view. The
background color appears underneath all other content in the view.
Using Appearance Proxies
You can use an appearance proxy to set particular appearance properties for all instances of a view in your
application. For example, if you want all sliders in your app to have a particular minimum track tint color, you
can specify this with a single message to the slider’s appearance proxy.
There are two ways to customize appearance for objects: for all instances and for instances contained within
an instance of a container class.
● To customize the appearance of all instances of a class, use appearance to get the appearance proxy for
the class.
[[UISlider appearance] setMinimumTrackTintColor:[UIColor greenColor]];
● To customize the appearances for instances of a class when contained within an instance of a container
class, or instances in a hierarchy, you use appearanceWhenContainedIn: to get the appearance proxy
for the class.
[[UISlider appearanceWhenContainedIn:[UIView class], nil]
setMinimumTrackTintColor:[UIColor greenColor]];
About Views
Configuring Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
18
Note: You cannot use the appearance proxy with the tintColor property on UIView. For more
information on using tintColor, see “Adjusting View Tint Color” (page 19).
Adjusting View Tint Color
Views have a tintColor property that specifies the color of key elements within the view. Each subclass of
UIView defines its own appearance and behavior for tintColor. For example, this property determines the
color of the outline, divider, and glyphs on a stepper:
The tintColor property is a quick and simple way to skin your app with a custom color. Setting a tint color
for a view automatically sets that tint color for all of its subviews. However, you can manually override this
property for any of those subviews and its decendants. In other words, each view inherits its superview’s tint
color if its own tint color is nil. If the highest level view in the view heirarchy has a nil valur for tint color, it
defaults to the system blue color.
Using Template Images
In iOS 7, you can choose to treat any of the images in your app as a template—or stencil—image. When you
elect to treat an image as a template, the system ignores the image’s color information and creates an image
stencil based on the alpha values in the image (parts of the image with an alpha value of less than 1.0 get
treated as completely transparent). This stencil can then be recolored using tintColor to match the rest of
your user interface.
By default, an image (UIImage) is created with UIImageRenderingModeAutomatic. If you have
UIImageRenderingModeAutomatic set on your image, it will be treated as template or original based on
its context. Certain UIKit elements—including navigation bars, tab bars, toolbars, segmented
controls—automatically treat their foreground images as templates, although their background images are
treated as original. Other elements—such as image views and web views—treat their images as originals. If
you want your image to always be treated as a template regardless of context, set
UIImageRenderingModeAlwaysTemplate; if you want your image to always be treated as original, set
UIImageRenderingModeAlwaysOriginal.
To specify the rendering mode of an image, first create a standard image, and then call the
imageWithRenderingMode: method on that image.
UIImage *myImage = [UIImage imageNamed:@"myImageFile.png"];
myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
About Views
Configuring Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
19
Using Auto Layout with Views
The Auto Layout system allows you to define layout constraints for user interface elements, such as views and
controls. Constraints represent relationships between user interface elements. You can create Auto Layout
constraints by selecting the appropriate element or group of elements and selecting an option from the menu
in the bottom right corner of Xcode’s Interface Builder.
Auto layout contains two menus of constraints: pin and align. The Pin menu allows you to specify constraints
that define some relationship based on a particular value or range of values. Some apply to the control itself
(width) while others define relationships between elements (horizontal spacing). The following tables describes
what each group of constraints in the Auto Layout menu accomplishes:
PurposeConstraint Name
Sets the width or height of a single element.
Sets the horizontal or vertical spacing between exactly two elements.
Sets the spacing from one or more elements to the leading, trailing, top,
or bottom of their container view. Leading and trailing are the same as
left and right in English, but the UI flips when localized in a right-to-left
environment.
Sets the widths or heights of two or more elements equal to each other.
Aligns the left, right, top, or bottom edges of two or more elements.
Aligns two or more elements according to their horizontal centers, vertical
centers, or bottom baselines. Note that baselines are different from bottom
edges. These values may not be defined for certain elements.
Aligns the horizontal or vertical centers of one or more elements with
the horizontal or vertical center of their container view.
About Views
Using Auto Layout with Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
20
The “Constant” value specified for any Pin constraints (besides Widths/Heights Equally) can be part of a
“Relation.” That is, you can specify whether you want the value of that constraint to be equal to, less than or
equal to, or greater than or equal to the value.
For more information, see Cocoa Auto Layout Guide.
Making Views Accessible
To enhance the accessibility information for an item, select the object on the storyboard and open the
Accessibility section of the Identity inspector.
For more information, see Accessibility Programming Guide for iOS.
Debugging Views
When debugging issues with views, watch for this common pitfall:
Setting conflicting opacity settings. You should not set the opaque property to YES if your view has an alpha
value of less than 1.0.
About Views
Making Views Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
21
Action sheets display a set of buttons representing several alternative choices to complete a task initiated by
the user. For example, when the user taps the Share button in an app’s toolbar, an action sheet appears offering
a list of choices, such as Email, Print, and so on.
Action sheets allow the user to:
● Quickly select from a list of actions
● Confirm or cancel an action
Implementation: Action sheets are implemented in the UIActionSheet class and discussed in the
UIActionSheet Class Reference.
Configuring Action Sheets
Action sheets are created, initialized, and configured in code, typically residing in a view controller
implementation file. You cannot create or manipulate action sheets in Interface Builder. Rather, an action sheet
appears over an existing view, interrupting its presentation, and it requires the user to dismiss it by tapping
one of its buttons (or tapping outside the action sheet on iPad). The chosen action is handled by the action
sheet’s delegate.
Setting Action Sheet Content Programmatically
When you create an action sheet object from the UIActionSheet class, you can initialize its most important
properties with one method,
initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:.
Depending on your app’s needs, that single message may be enough to configure a fully functional action
sheet object, as shown in the following code. Once you have created the action sheet object, send it a show...
message, such as showInView: to display the action sheet.
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete Note"
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
22
Action Sheets
otherButtonTitles:nil];
Although the first parameter of the
initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
method enables you to provide a title for an action sheet, iOS human interface guidelines recommend that
you do not use a title.
As described in iOS human interface guidelines, you should include a Cancel button with action sheets displayed
on iPhone and with those displayed on iPad over an open popover. Otherwise on iPad, action sheets are
displayed within a popover, and the user can cancel the action sheet by tapping outside the popover, in which
case you do not need to include a Cancel button.
To create a Cancel button, pass a non-nil value for the cancelButtonTitle: parameter of the
initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
method. A Cancel button created in this way is positioned at the bottom of the action sheet.
When your action sheet presents a potentially destructive choice, you should include a destructive button by
passing a non-nil value for the destructiveButtonTitle: parameter of the
initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
method. A destructive button created in this way is automatically colored red and positioned at the top of the
action sheet.
Specifying Action Sheet Behavior Programmatically
You can choose to present an action sheet so that it originates from a toolbar, tab bar, button bar item, from
a view, or from a rectangle within a view. On iPhone, because the action sheet slides up from the bottom of a
view and covers the width of the screen, most apps use showInView:. On iPad, however, action sheets appear
within a popover whose arrow points to the control the user tapped to invoke the choices presented by the
action sheet. So, showFromRect:inView:animated: and showFromBarButtonItem:animated: are most
useful on iPad.
To handle the choices presented by your action sheet, you must designate a delegate to handle the button’s
action, and the delegate must conform to the UIActionSheetDelegate protocol. You designate the delegate
with the delegate parameter when you initialize the action sheet object. The delegate must implement the
actionSheet:clickedButtonAtIndex: message to respond when the button is tapped. For example, the
following code shows an implementation that simply logs the title of the button that was tapped.
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
Action Sheets
Configuring Action Sheets
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
23
NSLog(@"The %@ button was tapped.", [actionSheet
buttonTitleAtIndex:buttonIndex]);
}
Using Auto Layout with Action Sheets
The layout of action sheets is handled for you. You cannot create Auto Layout constraints between an action
sheet and another user interface element.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Action Sheets Accessible
Action sheets are accessible by default.
Accessibility for action sheets primarily concerns button titles. If VoiceOver is activated, it speaks the word
“alert” when an action sheet is shown, then speaks its title if set (although iOS human interface guidelines
recommend against titling action sheets). As the user taps a button in the action sheet, VoiceOver speaks its
title and the word “button.”
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Action Sheets
To internationalize an action sheet, you must provide localized translations of the button titles. Button size
may change depending on the language and locale.
For more information, see Internationalization Programming Topics.
Debugging Action Sheets
When debugging issues with action sheets, watch for this common pitfall:
Action Sheets
Using Auto Layout with Action Sheets
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
24
Not testing localizations. Be sure to test the action sheets in your app with the localizations you intend to
ship. In particular, button titles can truncate if they are longer in localizations other than the one in which you
designed your user interface. Following the HI guideline to give buttons short, logical titles helps to ameliorate
this potential problem, but localization testing is also required.
Elements Similar to an Action Sheet
The following elements provide similar functionality to an action sheet:
● Alert View. Use an alert view to convey important information about an app or the device, interrupting
the user and requiring them to stop what they’re doing to choose an action or dismiss the alert. For more
information, see “Alert Views” (page 30).
● Modal View. Use a modal view (that is, the view controller uses a modal presentation style) when users
initiate a self-contained subtask in the context of their workflow or another task. For more information,
see UIViewController Class Reference.
Action Sheets
Elements Similar to an Action Sheet
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
25
An activity indicator is a spinning wheel that indicates a task is in the midst of being processed. If an action
takes a noticeable and indeterminate amount of time to process—such as a CPU-intensive task or connecting
to a network—you should display an activity indicator to give assurance to the user that your app is not stalled
or frozen.
Activity indicators allow the user to:
● Receive feedback that the system is processing information
Implementation: Activity indicators are implemented in the UIActivityIndicatorView class and discussed
in the UIActivityIndicatorView Class Reference.
Configuring Activity Indicators
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Activity Indicator Values
An activity indicator is indeterminate, and has no starting or ending values associated with it.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
26
Activity Indicators
Specifying Activity Indicator Behavior
The Animating (isAnimating) box is unchecked by default; checking it causes the activity indicator to start
animating. This is the equivalent of calling the startAnimating method.
Select the Hides When Stopped (hidesWhenStopped) field in the Attributes Inspector for your activity indicator
to disappear when the animation ends. When you call the startAnimating and stopAnimating methods,
the activity indicator automatically shows and hides onscreen. This way, you won’t have to worry about
displaying a stationary activity indicator.
Customizing Activity Indicator Appearance
You can customize the appearance of an activity indicator by setting the properties depicted below.
To customize the appearance of all activity indicators in your app, use the appearance proxy (for example,
[UIActivityIndicatorView appearance]). For more information about appearance proxies, see “Using
Appearance Proxies” (page 18).
Setting Activity Indicator Style
The Style (activityIndicatorViewStyle) field represents the predefined style of the activity indicator.
Use the style to specify one of two default colors: white or gray. You can also select a larger size for your
indicator using the “Large White” style option.
Activity Indicators
Configuring Activity Indicators
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
27
The Color (color) field allows you to specify a custom color for your indicator. This property takes precedence
over any color set using the Style field. However, if your style is set to Large White, your activity indicator
appears a larger size. Make sure your indicator is set to a different style option if you want to use the small
indicator.
Using Auto Layout with Activity Indicators
You can create Auto Layout constraints between an activity indicator and other UI elements.
Typically, activity indicators appear before a label or centered within a view. To align with a label, constrain
Bottom Edges and Horizontal Space to the label with the standard value. To center within a view, add the
Horizontal Center in Container and Vertical Center in Container constraints.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Activity Indicators Accessible
Activity indicators are accessible by default. The default accessibility trait for an activity indicator is User
Interaction Enabled.
If you have a label next to your activity indicator that describes the processing task in more detail, you might
want to disable its accessibility with the isAccessibilityElement property so VoiceOver reads the label
instead. Otherwise, VoiceOver reads “In progress” while the activity indicator is animating, and “Progress halted”
while it is not.
VoiceOver will read only elements that are visible onscreen. If you enable the hidesWhenStopped property,
VoiceOver might abruptly stop speaking when the animation finishes.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Activity Indicators
Using Auto Layout with Activity Indicators
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
28
Internationalizing Activity Indicators
Activity indicators have no special properties related to internationalization. However, if you use an activity
indicator with a label, make sure you provide localized strings for the label.
For more information, see Internationalization Programming Topics.
Debugging Activity Indicators
When debugging issues with activity indicators, watch for this common pitfall:
Specifying conflicting appearance settings. The color property takes precedence over any color set using
the activityIndicatorViewStyle property. However, if your style is set to Large White, your activity
indicator appears a larger size with whatever custom color you set. Make sure your indicator is set to a different
style option if you want to use the small indicator.
Elements Similar to an Activity Indicator
The following element provides similar functionality to an activity indicator:
Progress View. A class that represents a progress bar. Use this class instead of an activity indicator when your
task takes a determinate amount of time. For more information, see “Progress Views” (page 65).
Activity Indicators
Internationalizing Activity Indicators
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
29
Alert views display a concise and informative alert message to the user. Alert views convey important information
about an app or the device, interrupting the user and requiring them to stop what they’re doing to choose an
action or dismiss the alert. For example, iOS uses alerts to warn the user that battery power is running low, so
they can connect a power adapter before their workflow is interrupted. An alert view appears on top of app
content, and must be manually dismissed by the user before he can resume interaction with the app.
Alert views allow the user to:
● Be immediately informed of critical information
● Make a decision about a course of action
Implementation: Alert views are implemented in the UIAlertView class and discussed in the UIAlertView
Class Reference.
Configuring Alert Views
Alert views are created, initialized, and configured in code, typically residing in a view controller implementation
file. You cannot create or manipulate alert views in Interface Builder. Rather, an alert view floats over an existing
view to interrupt its presentation, and it requires the user to dismiss it. If the alert view contains a custom
button enabling the user to choose an alternative action, rather than simply dismissing the alert, that action
is handled by the alert view’s delegate.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
30
Alert Views
Setting Alert View Content Programmatically
When setting alert view content, you can control the number of buttons, their titles, displayed text, and inclusion
of one or two text fields, one of which can be a secure text-input field.
When you create an alert view object from the UIAlertView class, you can initialize its most important
properties with one method,
initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:. Depending on your
app’s needs, that single message may be enough to configure a fully functional alert object, as shown in the
following code. After you have created the alert object, send it a show message to display the alert.
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"This is the message."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[theAlert show];
Every alert has a Cancel button so that the user can dismiss the alert. You can add additional, custom buttons
to enable the user to perform some other action related to the alert, such as rectifying the problem the alert
warned about. Although you can add multiple custom buttons to an alert, iOS Human Interface Guidelines
recommend that you limit alerts to two buttons, and consider using an action sheet instead if you need more.
To add a titled custom button to an alert, send it an addButtonWithTitle: message. Alternatively, you can
pass the custom button title, followed by a comma and nil terminator, with the otherButtonTitles:
parameter when you initialize the alert view object.
Alert Views
Configuring Alert Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
31
Optionally, an alert can contain one or two text fields, one of which can be a secure text-input field. You add
text fields to an alert after it is created by setting its alertViewStyle property to one of the styles specified
by the UIAlertViewStyle constants. The alert view styles can specify no text field (the default style), one
plain text field, one secure text field (which displays a bullet character as each character is typed), or two text
fields (one plain and one secure) to accommodate a login identifier and password.
Specifying Alert View Behavior Programmatically
If your alert has a custom button, you must designate a delegate to handle the button’s action, and the delegate
must conform to the UIAlertViewDelegate protocol. You designate the delegate with the delegate
parameter when you initialize the alert view object. The delegate must implement the
alertView:clickedButtonAtIndex: message to respond when the custom button is tapped; otherwise,
your custom buttons do nothing. For example, the following code shows an implementation that simply logs
the title of the button that was tapped:
- (void)alertView:(UIAlertView *)theAlert clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"The %@ button was tapped.", [theAlert buttonTitleAtIndex:buttonIndex]);
}
In the delegate method alertView:clickedButtonAtIndex:, depending on which button the user tapped,
you can retrieve the values of text fields in your alert view with the textFieldAtIndex: method.
if (theAlert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput) {
NSLog(@"The login field says %@, and the password is %@.",
[theAlert textFieldAtIndex:0].text, [theAlert textFieldAtIndex:1].text);
}
Alert Views
Configuring Alert Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
32
The alert view is automatically dismissed after the alertView:clickedButtonAtIndex: delegate method
is invoked. Optionally, you can implement the alertViewCancel: method to take the appropriate action
when the system cancels your alert view. An alert view can be canceled at any time by the system—for example,
when the user taps the Home button. If the delegate does not implement the alertViewCancel: method,
the default behavior is to simulate the user clicking the cancel button and closing the view.
Customizing Alert View Appearance
You cannot customize the appearance of alert views.
Using Auto Layout with Alert Views
The layout of alert views is handled for you. You cannot create Auto Layout constraints between an alert view
and another user interface element.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Alert Views Accessible
Alert views are accessible by default.
Accessibility for alert views pertains to the alert title, alert message, and button titles. If VoiceOver is activated,
it speaks the word “alert” when an alert is shown, then speaks its title followed by its message if set. As the
user taps a button, VoiceOver speaks its title and the word “button.” As the user taps a text field, VoiceOver
speaks its value and “text field” or “secure text field.”
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Alert Views
To internationalize an alert view, you must provide localized translations of the alert title, message, and button
titles. Screen metrics and layout may change depending on the language and locale.
For more information, see Internationalization Programming Topics.
Alert Views
Using Auto Layout with Alert Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
33
Debugging Alert Views
When debugging issues with sliders, watch for this common pitfall:
Not testing localizations. Be sure to test the alert views in your app with the localizations you intend to ship.
In particular, button titles can truncate if they are longer in localizations other than the one in which you
designed your user interface. Following the HI guideline to give buttons short, logical titles helps to ameliorate
this potential problem, but localization testing is also required.
Elements Similar to an Alert View
The following elements provide similar functionality to an alert view:
● Action Sheet. Present an action sheet when users tap a button in a toolbar, giving them choices related
to the action they’ve initiated. For more information, see “Action Sheets” (page 22).
● Modal View. Present a modal view (that is, the view controller uses a modal presentation style) when
users initiate a subtask in the context of their workflow or another task. For more information, see
UIViewController Class Reference.
Alert Views
Debugging Alert Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
34
A collection view displays an ordered collection of data items using standard or custom layouts. Similar to a
table view, a collection view gets data from your custom data source objects and displays it using a combination
of cell, layout, and supplementary views. A collection view can display items in a grid or in a custom layout
that you design. Regardless of the layout style you choose, a collection view is best suited to display
nonhierarchical, ordered data items.
Collection views allow the user to:
● View a catalog of variably sized items, optionally sorted into multiple sections
● Add to, rearrange, and edit a collection of items
● Choose from a frequently changing display of items
Implementation:
● Collection views are implemented in the UICollectionView class and discussed in the UICollectionView
Class Reference.
● Collection view cells are implemented in the UICollectionViewCell class and discussed in the
UICollectionViewCell Class Reference.
● Collection reusable views are implemented in the UICollectionReusableView class and discussed in
the UICollectionReusableView Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
35
Collection Views
Configuring Collection Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Collection View Content
Cells present the main content of your collection view. The job of a cell is to present the content for a single
item from your data source object. Each cell must be an instance of the UICollectionViewCell class, which
you may subclass as needed to present your content. Cell objects provide inherent support for managing their
own selection and highlight state, although some custom code must be written to actually apply a highlight
to a cell. A UICollectionViewCell object is a specific type of reusable view that you use for your main data
items.
To manage the visual presentation of data, a collection view works with many related classes, such as
UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate,
UICollectionReusableView, UICollectionViewCell, UICollectionViewLayout, and
UICollectionViewLayoutAttributes.
Collection views enforce a strict separation between the data being presented and the visual elements used
for presentation. Your app is solely responsible for managing the data via your custom data source objects.
(To learn how to create these objects, see “Designing Your Data Objects” in Collection View Programming Guide
Collection Views
Configuring Collection Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
36
for iOS.) Your app also provides the view objects used to present that data. The collection view takes your
views and—with the help of a layout object, which specifies placement and other visual attributes—does all
the work of displaying them onscreen.
To display content onscreen in an efficient way, a collection view uses the following reusable view objects:
● Cell. Represents one data item.
● Supplementary view. Represents information related to the data items, such as a section header or footer.
● Decoration view. Represents purely decorative content that’s not part of your data, such as a background
image.
Because a collection view works with these and other objects to determine the visual presentation of your
data, configuring a collection view in Interface Builder means that you need to configure some objects separately.
● Items. The number of different types of data for which you define distinct cell objects. If your app works
with only one type of data item—regardless of the total number of data items you display—set this value
to 1.
● Accessories. The existence of a header or footer view for each section (this property isn’t available for
custom layouts). Select Section Header or Section Footer as appropriate.
In Collection Reusable View Attributes inspector—which governs supplementary views, decoration views, and
cells—you can set the Identifier (identifier) field. Enter the ID you use in your code to identify the reusable cell,
decoration, or supplementary view object.
Specifying Collection View Behavior
There are several behaviors you can support in your collection view. For example, you might want to allow
users to:
● Select one or more items
● Insert, delete, and reorder items or sections
● Edit an item
Collection Views
Configuring Collection Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
37
By default, a collection view detects when the user taps a specific cell and it updates the cell’s selected or
highlighted properties as appropriate. You can write code that configures a collection view to support
multiple-item selection or that draws the selected or highlighted states yourself. To learn how to support
multiple selection or custom selection states, see “Managing the Visual State for Selections and Highlights” in
Collection View Programming Guide for iOS.
To support insertion, deletion, or reordering of cells in a collection view, you make changes to your data source
and then tell the collection view to redisplay the content. By default, a collection view animates the insertion,
deletion, or movement of a single item; if you want to animate these changes for multiple items at once, you
use code blocks to batch the update. To learn how animate multiple changes to a collection view, see “Inserting,
Deleting, and Moving Sections and Items” in Collection View Programming Guide for iOS. To let users move an
item or items by dragging, you also need to incorporate a custom gesture recognizer. (To learn how to do this,
see “Manipulating Cells and Views” in Collection View Programming Guide for iOS.)
If you support editing for an item, the collection view automatically displays the Edit menu when it detects a
long-press gesture on a specific cell. To learn how to support editing in a collection view, see “Showing the
Edit Menu for a Cell” in Collection View Programming Guide for iOS.
When configuring cells and supplementary views in a storyboard, you do so by dragging the item onto your
collection view and configuring it there. This creates a relationship between the collection view and the
corresponding cell or view. For cells, drag a collection view cell from the object library and drop it onto your
collection view. Set the custom class and the collection reusable view identifier of your cell to appropriate
values.
Whether the user is selecting or deselecting a cell, the cell’s selected state is always the last thing to change.
Taps in a cell always result in changes to the cell’s highlighted state first. Only after the tap sequence ends and
any highlights applied during that sequence are removed, does the selected state of the cell change. When
designing your cells, you should make sure that the visual appearance of your highlights and selected state
do not conflict in unintended ways.
When the user performs a long-tap gesture on a cell, the collection view attempts to display an Edit menu for
that cell. The Edit menu can be used to cut, copy, and paste cells in the collection view.
If you’re working with the UICollectionViewFlowLayout class, you can use the Attributes inspector to set
the “Scroll Direction” (scrollDirection) field to Horizontal or Vertical. Note that this property isn’t
available for custom layouts.
Collection Views
Configuring Collection Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
38
Customizing Collection View Appearance
Specifying Collection View Layout
A collection view relies on a layout object to define the layout of its cells, supplementary views, and decoration
views.
The Layout field determines the layout of the cells. The default value is Flow, which refers to the layout defined
by the UICollectionViewFlowLayout class. If you provide a custom layout class, choose Custom instead.
To learn more about creating a custom layout class, see Collection View Programming Guide for iOS.
Setting Collection View Background
To use a custom background for a collection view, you can specify a view that's positioned underneath all of
the other content and sized automatically to fill the entire bounds of the collection view. You can set this value
using the backgroundView property. Because this background view doesn’t scroll with the collection view’s
content, it’s not an appropriate way to display a decorative background such as the appearance of wooden
shelves.
Setting Collection View Cell Background
To use a custom background for a single collection view cell, you can specify a view that’s positioned behind
the cell’s content view and that fills the cell’s bounds. You can set this value using the backgroundView
property.
You can also specify a custom selected background by providing a view that’s displayed above the cell’s
background view—and behind the content view—when the user selects the cell. Set this value using the
selectedBackgroundView property.
Adjusting Collection View Spacing
In the Collection View Flow Layout Size Inspector, you can set size values (in points) for the layout object to
use when laying out cells and supplementary views.
For spacing between cells you can set the following Min Spacing values:
Collection Views
Configuring Collection Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
39
● For Cells. The minimum space to maintain between cells on one line.
● For Lines. The minimum space to maintain between lines of cells.
Adjusting Collection View Cell Padding
To add padding around cells so that space appears above, below, or on either side of the cells in a section, use
the “Section Insets” fields in the Collection View Flow Layout Size Inspector. Specifying nonzero inset values
reduces the amount of space available for laying out cells, which lets you limit the number of cells that can
appear on one row or the number of rows that can appear in one section. The insets you can specify are:
● Top. The space to add between the bottom of the header view and the top of the first line of cells.
● Bottom. The space to add between the bottom last line of cells and the top of the footer
● Left. The space to add between the left edge of the cells and the left edge of the collection view.
● Right. The space to add between the right edge of the cells and the right edge of the collection view.
Using Auto Layout with Collection Views
You can create Auto Layout constraints between a collection view and other user interface elements. You can
create any type of constraint for a collection view besides a baseline constraint.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Collection Views Accessible
The data items in a collection view are accessible by default when they are represented by standard UIKit
objects, such as UILabel and UITextField.
When a collection view changes its onscreen layout, it posts the
UIAccessibilityLayoutChangedNotification notification.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Collection Views
Using Auto Layout with Collection Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
40
Internationalizing Collection Views
For more information, see Internationalization Programming Topics.
Elements Similar to a Collection View
The following elements provide similar functionality to a collection view:
● Table View. A scrolling view that displays data items in a single-column list. For more information, see
“Table Views” (page 88).
● Scroll View. A scrolling view that displays content without support for any specific layout or ordering
scheme. For more information, see “Scroll Views” (page 69).
Collection Views
Internationalizing Collection Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
41
An image view displays an image or an animated sequence of images. An image view lets you efficiently draw
an image (such as a JPEG or PNG file) or an animated series of images onscreen, scaling the images automatically
to fit within the current size of the view. Image views can optionally display a different image or series of images
whenever the view is highlighted. Image views support the same file formats as the UIImage class—TIFF,
JPEG, PNG, Windows bitmap (bmp), Windows icon (ico), Windows cursor (cur), and X Window System bitmap
(xbm) formats.
Image views allow the user to:
● View images within an app
Implementation: Image views are implemented in the UIImageView class and discussed in the UIImageView
Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
42
Image Views
Configuring Image Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
In addition, image views provide significant programmatic customization by modifying properties on the view
objects and properties on whatever image object you have loaded into the view.
Setting Image View Content
If you are displaying a single image, most image views require minimal configuration beyond setting the image.
If you are displaying an animated series of images, you must also configure the animation settings.
When you first use an image view object to display a single image, you can select an image to display using
the Image (image) field in the Attributes Inspector. If you did not choose an image in the Attributes Inspector,
you must set the initial image by calling initWithImage: or by setting the image property to a UIImage
object that describes the image you want to display.
If you want to show a different image when the view is highlighted, you can specify this information in the
Highlighted (highlightedImage) field. Alternatively, either call initWithImage:highlightedImage:
when you initialize the image or set the highlightedImage property to the alternative image.
If you want your image view to display an animated sequence of images, you must do this programmatically.
Because you cannot specify an array of images in the Attributes Inspector, you must write some code to tell
the image view which images to use. To do this, set the animationImages property to an array of UIImage
objects in the order in which they should be shown. Optionally set the highlightedAnimationImages
property if you want to show a different animation while the view is highlighted.
Image Views
Configuring Image Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
43
Important: All images associated with a UIImageView object should have the same scale value. If your
application uses images with different scales, they may render incorrectly.
Specifying Image View Behavior
Use the Highlighted (highlighted) checkbox to specify whether the view should show the standard or
highlighted image or image sequence.
You can change the image view’s state at any time.
If you are using an image sequence, you can instead configure the animation behavior programmatically:
● Set the animationDuration to the desired animation period (in seconds). By default, this property is
computed based on the number of images at 30 frames per second.
● Set the animationRepeatCount to limit the number of iterations through the set of images. By default,
this property has a value of zero, which means that the animation repeats forever.
You start the animation by calling startAnimating.
Customizing Image View Appearance
You cannot customize the appearance of an image view directly. However, you can determine how images
appear in the view by setting properties at the UIImage and UIView levels.
Setting View Content Mode
The view’s contentMode property specifies how the image should be scaled and aligned within the view. It
is recommended (but not required) that you use images that are all the same size. If the images are different
sizes, each will be adjusted to fit separately based on this mode.
Creating Images
The image’s capInsets, leftCapWidth, and topCapHeight properties specify the width and height of a
central portion of the image that should be scaled differently than the border areas (outside that central
portion). The top and bottom border areas are tiled horizontally. The left and right border areas are tiled
vertically. The corners are displayed as-is. Additionally, the image’s alignmentRectInsets property specifies
portions of the image to ignore for alignment purposes (such as shadow and glow effects).
Image Views
Configuring Image Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
44
You can create images for images views in a number of ways, including:
● Using the imageWithAlignmentRectInsets: method, which returns a derived image with nonzero
alignment insets.
● Using the resizableImageWithCapInsets: or resizableImageWithCapInsets:resizingMode:
methods, which return a derived static image with nonzero cap insets. The image’s resizingMode
property indicates whether the image should be scaled or tiled.
● Using the animatedResizableImageNamed:capInsets:duration: or
animatedResizableImageNamed:capInsets:resizingMode:duration: methods, which return
a derived animated image with nonzero cap insets.
These methods cannot be set after the image is created or loaded.
Customizing Image Transparency and Alpha Blending
Transparency of an image view is defined by properties of both the underlying image and the view as follows:
● If the view’s Opaque (opaque) flag is set, the image is alpha blended with the background color of the
view, and the view itself is opaque. The view’s Alpha (alpha) setting is ignored.
● If the view’s Opaque (opaque) flag is not set, the alpha channel for each pixel (or 1.0 if the image has no
alpha channel) is multiplied by the view’s Alpha (alpha) setting, and the resulting value determines the
transparency for that pixel.
Important: It is computationally expensive to perform alpha compositing of non-opaque image views
containing images with alpha channels. If you are not intentionally using the image alpha channel or the
view’s Alpha setting, you should set the Opaque flag to improve performance. See the last bullet point of
“Debugging Image Views” (page 46) for more information.
Using Auto Layout with Image Views
You can create Auto Layout constraints between a image view and other user interface elements. You can
create any type of constraint for a image view besides a baseline constraint.
You generally want the image view to fill the full width of your screen. To ensure that this happens correctly
on all devices and orientations, you can create Leading Space to Superview and Trailing Space to Superview
constraints, and set both values equal to 0. This will ensure that the image view remains pinned to the edges
of the device screen.
Image Views
Using Auto Layout with Image Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
45
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Image Views Accessible
Image views are accessible by default. The default accessibility traits for a image view are Image and User
Interaction Enabled.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Image Views
Internationalization of image views is automatic if your view displays only static images loaded from your app
bundle. If you are loading images programmatically, you are at least partially responsible for loading the correct
image.
● For resources in your app bundle, you do this by specifying the name in the attributes inspector or by
calling the imageNamed: class method on UIImage to obtain the localized version of each image.
● For images that are not in your app bundle, your code must do the following:
1. Determine which image to load in a manner specific to your app, such as providing a localized string
that contains the URL.
2. Load that image by passing the URL or data for the correct image to an appropriate UIImage class
method, such as imageWithData: or imageWithContentsOfFile:.
Tip: Screen metrics and layout may also change depending on the language and locale, particularly if the
internationalized versions of your images have different dimensions. Where possible, you should try to make
minimize dimension differences in internationalized versions of image resources.
For more information, see Internationalization Programming Topics.
Debugging Image Views
When debugging issues with image views, watch for these common pitfalls:
Image Views
Making Image Views Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
46
● Not loading your image with the correct method. If you are loading an image from your app bundle,
use imageNamed:. If you are loading an image from a file (with a full path or URL), use
imageWithContentsOfFile:.
● Not making animated image frames the same size. This helps you avoid having to deal with scaling,
tiling, or positioning differences between frames.
● Not using a consistent scale value for all animated image frames. Mixing images with different scale
factors may produce undefined behavior.
● Doing custom drawing in a subclass of an image view. The UIImageView class is optimized to draw its
images to the display. UIImageView does not call the drawRect: method of its subclasses. If your subclass
needs to include custom drawing code, you should subclass the UIView class instead.
● Not enabling event handling in subclasses if you need it. New image view objects are configured to
disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you
must explicitly change the value of the userInteractionEnabled property to YES after initializing the
object.
● Not providing prescaled images where possible. For example, if you expect certain large images to be
frequently displayed in a scaled-down thumbnail view, you might consider keeping the scaled-down
images in a thumbnail cache. Scaling the image is a relatively expensive operation.
● Not limiting image size. Consider prescaling or tiling large images. The MVCNetworking sample code
project (QImageScrollView.m) demonstrates how to determine what model of iOS device your software
is running on. You can then use that information to help you determine the image dimension thresholds
to use when scaling or tiling.
● Not disabling alpha blending except where needed. Unless you are intentionally working with images
that contain transparency (drawing UI elements, for example), you should generally mark the view as
opaque by selecting the Opaque checkbox in the Attributes Inspector, or setting the opaque property on
the view itself.
For views that are not opaque, the device must perform a lot of unnecessary computation if alpha blending
is enabled and the image contains an alpha channel. This performance impact is further magnified if you
are using Core Animation shadows, because the shape of the shadow is then based on the contents of
the view, and must be dynamically computed.
To learn more about how alpha blending works, see “Customizing Image Transparency and Alpha
Blending” (page 45).
Elements Similar to an Image View
The following elements provide similar functionality to a web view:
Image Views
Elements Similar to an Image View
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
47
● Button. You can set the background image of a button control (of type UIButtonTypeCustom). For more
information, see “Buttons” (page 123).
● Scroll View. An image view typically scales content up or down to fit the dimensions of the view. If you
need to display an image with user-controlled zooming and scaling, you should place that image view
inside a scroll view. For more information, see “Scroll Views” (page 69).
● Custom Views. If you create a custom subclass of UIView, you can programmatically draw images inside
its drawRect: method. (For maximum performance, you should do this only when absolutely necessary.)
For more information, see “About Views” (page 14).
Image Views
Elements Similar to an Image View
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
48
A label displays static text. Labels are often used in conjunction with controls to describe their intended purpose,
such as explaining which value a button or slider affects.
Labels allow the user to:
● Understand the purpose of controls in an app
● Receive instructions or context in an app
Implementation: Labels are implemented in the UILabel class and discussed in the UILabel Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
49
Labels
Configuring Labels
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Labels
Configuring Labels
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
50
Setting Label Content
Set label content using the Label Text (text and attributedText) field in the Attributes Inspector. Both
properties get set whether you specified the value of the Text field to be plain or attributed. For more information
about attributed text, see “Specifying Text Appearance” (page 52).
By default, a label is a single line. To create a multiline label, increase the value of the Lines (numberOfLines)
field.
Specifying Label Behavior
You can specify whether a label is enabled or highlighted using the Enabled (enabled) and Highlighted
(highlighted) checkboxes in the Attributes Inspector.
The Autoshrink (adjustsFontSizeToFitWidth) field is used to specify the manner in which font size will
be reduced with the label’s bounding rectangle.
The Fixed Font Size option is the equivalent of setting adjustsFontSizeToFitWidth to NO, meaning that
font size will not adjust. Select the Minimum Font Scale (minimumScaleFactor) option to specify the smallest
multiplier for the current font size that the font can scale down to, and the Minimum Font Size
(minimumFontSize) option to specify the smallest font size that the font can scale down to.
Labels
Configuring Labels
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
51
Select the Tighten Letter Spacing (adjustsLetterSpacingToFitWidth) checkbox if you want the spacing
between letters to be adjusted to fit the string within the label’s bounding rectangle.
The Baselines (baselineAdjustment) field determines how to adjust the position of text in cases when the
text must be drawn using a different font size than the one originally specified. For example, with the Align
Baselines option, the position of the baseline remains fixed at its initial location while the text appears to move
toward that baseline. Similarly, selecting the None option makes it appear as if the text is moving upwards
toward the top-left corner of the bounding box.
Use the Line Breaks (lineBreakMode) field to specify the technique to use for wrapping and truncating the
label’s text if it exceeds a single line. Note that if this property is set to a value that causes text to wrap to
another line, do not set the adjustsFontSizeToFitWidth or adjustsLetterSpacingToFitWidth
property to YES.
Customizing Label Appearance
You can customize the appearance of a label by setting the properties depicted below.
To customize the appearance of all labels in your app, use the appearance proxy (for example, [UILabel
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Specifying Text Appearance
Labels can have one of two types of text: plain or attributed. Plain text supports a single set of formatting
attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports
multiple sets of attributes that apply to individual characters or ranges of characters in the string.
Labels
Configuring Labels
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
52
Specifying Highlighted Appearance
By default, the highlighted appearance of a label is no different than that of its normal control state.
However, you can create a different look for your label when it’s in the UIControlStateHighlighted state
by modifying its color in the Highlighted (highlightedTextColor) field.
Setting a Text Shadow
You can set a color for your label’s shadow using the Shadow (shadowColor) field in the Attributes Inspector.
If you want to change how far the shadow is drawn from the button text, you can adjust the shadow offset.
You can customize the offset for both dimensions using the Shadow Offset (shadowOffset) fields.
Using Auto Layout with Labels
You can create Auto Layout constraints between a label and other user interface elements. You can create any
type of constraint for a label.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Labels Accessible
Labels are accessible by default. The default accessibility trait for a label are Static Text and User Interaction
Enabled.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Labels
Using Auto Layout with Labels
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
53
Internationalizing Labels
For more information, see Internationalization Programming Topics.
Debugging Labels
When debugging issues with labels, watch for this common pitfall:
Specifying conflicting text wrapping and font adjustment settings. The lineBreakMode property describes
how text should wrap or truncate within the label. If you set a value for this property that causes text to wrap
to another line, do not set the adjustsFontSizeToFitWidth and adjustsLetterSpacingToFitWidth
properties to YES, those fields ar used to scale the font size to fit into the label without adding line breaks.
Elements Similar to a Label
The following element provides similar functionality to a label:
Text Field. Text fields allows the user to input a single line of text into an app. You typically use text fields to
gather small amounts of text from the user and perform some immediate action, such as a search operation,
based on that text. For more information, see “Text Fields” (page 165).
Labels
Internationalizing Labels
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
54
Navigation bars allow you to present your app’s content in an organized and intuitive way. A navigation bar
is displayed at the top of the screen, and contains buttons for navigating through a hierarchy of screens. A
navigation bar generally has a back button, a title, and a right button. The most common way to use a navigation
bar is with a navigation controller. You can also use a navigation bar as a standalone object in your app.
Navigation bars allow the user to:
● Navigate to the previous view
● Transition to a new view
Implementation:
● Navigation bars are implemented in the UINavigationBar class and discussed in the UINavigationBar
Class Reference.
● Navigation items are implemented in the UINavigationItem class and discussed in the UINavigationItem
Class Reference.
● Bar button items are implemented in the UIBarButtonItem class and discussed in the UIBarButtonItem
Class Reference.
● Bar items are implemented in the UIBarItem class and discussed in the UIBarItem Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
55
Navigation Bars
Configuring Navigation Bars
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Navigation Bar Content
After you create a navigation bar, either in conjunction with a navigation controller or as a standalone object,
you need to add content to the bar. A navigation bar can display a left button, title, prompt string, and right
button.
The navigation bar displays information from a stack of UINavigationItem objects. At any given time, the
UINavigationItem that is currently the topItem of the stack determines the title and other optional
information in the navigation bar, such as the right button and prompt. The UINavigationItem that is
immediately below the topItem is the backItem, which determines the appearance of the left or back button.
You can also add bar button items to a UINavigationItem. A UIBarButtonItem generally has a title and
either a custom image or one of the system-supplied images listed in UIBarButtonSystemItem. It’s common
to have a right bar button, but you can also use a left bar button in the place of a back button.
Navigation Bars
Configuring Navigation Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
56
To add any of these elements to a navigation bar, select the desired item from the Object library in Interface
Builder and drag it to your storyboard. Then, you customize the contents in the Attributes Inspector as described
in “Setting Navigation Bar Images” (page 59).
Formoreinformationabouttheelementsthatyouaddtoanavigationbar,seeUINavigationItemClassReference
and UIBarButtonItem Class Reference.
Specifying Navigation Bar Behavior
The most common way to use a navigation bar is with a UINavigationController object. A navigation
controller manages the navigation between different screens of content for you. It also creates the navigation
bar automatically, and pushes and pops navigation items as appropriate.
You can add a navigation controller to your app in Interface Builder or programmatically. To use Interface
Builder to create a navigation controller, see “Creating a Navigation Interface Using a Storyboard” in View
Controller Catalog for iOS. To create a navigation controller programmatically, see “Creating a Navigation
Interface Programmatically” in View Controller Catalog for iOS.
A navigation controller automatically assigns itself as the delegate of its navigation bar object. Attempting to
change the delegate raises an exception. For more information about using a navigation bar with navigation
controller, see “Navigation Controllers”.
When you use a navigation bar as a standalone object, you set the initial appearance of the navigation bar by
creating the appropriate UINavigationItem objects and adding them to the navigation bar object stack.
When you create your standalone navigation bar in Interface Builder, Xcode creates the corresponding
UINavigationItem objects for the elements you drag to the navigation bar.
You are also responsible for managing the stack of UINavigationItem objects when you use a navigation
bar as a standalone object. You push new navigation items onto the stack using the
pushNavigationItem:animated: method and pop items off the stack using the
popNavigationItemAnimated: method. In addition to pushing and popping items, you can also set the
contents of the stack directly using either the items property or the setItems:animated: method. You
might use these methods at launch time to restore your interface to its previous state or to push or pop more
than one navigation item at a time.
Assign a custom delegate object to the delegate property and use that object to intercept messages sent
by the navigation bar. Delegate objects must conform to the UINavigationBarDelegate protocol. The
delegate notifications let you track when navigation items are pushed or popped from the stack. You use these
notifications to update the rest of your app’s user interface. For more information about implementing a
delegate object, see UINavigationBarDelegate Protocol Reference.
Navigation Bars
Configuring Navigation Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
57
Customizing Navigation Bar Appearance
You can customize the appearance of a navigation bar by setting the properties depicted below.
To customize the appearance of all navigation bars in your app, use the appearance proxy (for example,
[UINavigationBar appearance]). For more information about appearance proxies, see “Using Appearance
Proxies” (page 18).
Specifying Navigation Bar Style
Navigation bars have two standard appearance styles: translucent white with dark text (default) or translucent
black with light text. Use the Style (barStyle) field to select one of these standard styles.
Adjusting Navigation Bar Tint
You can specify a custom tint color for the navigation bar background using the Tint (barTintColor) field.
The default background tint color is white.
Additionally, you can set a custom tint color for the interactive elements within a navigation bar—including
button images and titles—programmatically using the tintColor property. The navigation bar will inherit
its superview’s tint color if a custom one is set, or show the default system blue color if none is set. For more
information, see “Adjusting View Tint Color” (page 19).
Navigation Bars
Configuring Navigation Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
58
Setting Navigation Bar Images
You can set a custom background image for your navigation bar. You can do this using
setBackgroundImage:forBarMetrics:. Note that you must specify bar metrics because navigation bars
have different dimensions on different devices and orientations.
You can also use a custom shadow image for the navigation bar using the shadowImage property. To show
a custom shadow image, you must also set a custom background image.
Setting Navigation Bar Translucency
Navigation bars are translucent by default in iOS 7. Additionally, there is a system blur applied to all navigation
bars. This allows your content to show through underneath the bar.
These settings automatically apply when you set any style for barStyle or any custom color for barTintColor.
If you prefer, you can make the navigation bar opaque by setting the translucent property to NO
programmatically. In this case, the bar draws an opaque background using black if the navigation bar has
UIBarStyleBlack style, white if the navigation bar has UIBarStyleDefault, or the navigation bar’s
barTintColor if a custom value is defined.
If the navigation bar has a custom background image, the default translucency is automatically inferred from
the average alpha values of the image. If the average alpha is less than 1.0, the navigation bar will be translucent
by default; if the average alpha is 1.0, the search bar will be opaque by default. If you set the translucent
property to YES on a navigation bar with an opaque custom background image, the navigation bar makes the
image translucent. If you set the translucent property to NO on a navigation bar with a translucent custom
background image, the navigation bar provides an opaque background for the image using black if the
navigation bar has UIBarStyleBlack style, white if the navigation bar has UIBarStyleDefault, or the
navigation bar’s barTintColor if a custom value is defined.
Formatting Navigation Bar Title
The titleTextAttributes property specifies the attributes for displaying the bar’s title text. You can specify
the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary,
using the text attribute keys described in NSString UIKit Additions Reference.
You can adjust the vertical position of a navigation bar’s title using the
setTitleVerticalPositionAdjustment:forBarMetrics: method. Note that you must specify bar
metrics because navigation bars have different dimensions for different devices and screen orientations.
Navigation Bars
Configuring Navigation Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
59
Setting Bar Button Item Glyphs
Any bar button in a navigation bar can have a custom image instead of text. You can provide this image to
your bar button item during initialization. Note that a bar button image will be automatically rendered as a
template image within a navigation bar, unless you explicitly set its rendering mode to
UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19).
Using Auto Layout with Navigation Bars
You can create Auto Layout constraints between a navigation bar and other user interface elements. You can
create any type of constraint for a navigation bar besides a baseline constraint.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Navigation Bars Accessible
Navigation bars are accessible by default. The default accessibility trait for a navigation bar is User Interaction
Enabled.
With VoiceOver enabled on an iOS device, after the user navigates to a new view in the hierarchy, VoiceOver
reads the navigation bar’s title, followed by the name of the left bar button item. When the user taps on an
element in a navigation bar, VoiceOver reads the name and the type of the element, such as, “General back
button,” “Keyboard heading,” and “Edit button.”
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Navigation Bars
For more information, see Internationalization Programming Topics.
Debugging Navigation Bars
When debugging issues with navigation bars, watch for this common pitfall:
Navigation Bars
Using Auto Layout with Navigation Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
60
Specifying conflicting appearance settings. When customizing navigation bar appearance with a style or
color, use one option or the other, but not both. Conflicting settings for navigation bar appearance will be
resolved in favor of the most recently set value. For example, setting a new style clears any custom tint color
you have set. Similarly, setting a custom tint color overrides any style you have set.
Elements Similar to a Navigation Bar
The following classes provide similar functionality to a navigation bar:
● Toolbar. A navigation controller can also manage a toolbar. On iPhone, this toolbar always appears at the
bottom edge of the screen, but on iPad a toolbar can appear at the top of the screen. You can create a
toolbar with a navigation controller, or as a standalone object. Unlike a navigation bar, which contains
controls for navigating through a hierarchy of screens, a toolbar contains controls that perform actions
related to the contents of the screen. For example, a toolbar might contain Share button and a Search
button. For more information about toolbars, see “Toolbars” (page 104).
● Tab Bar. Similar to a navigation bar, a tab bar allows the user to switch between different views. However,
a tab bar is persistent, which means that the user can select any tab from any other tab. By contrast, a
navigation bar presents a linear path through various screens. For more information about tab bars, see
“Tab Bars” (page 83).
Navigation Bars
Elements Similar to a Navigation Bar
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
61
A picker view lets the user choose between certain options by spinning a wheel on the screen. Picker views
are well suited for choosing things like dates and times (as the date picker does) that have a moderate number
of discrete options. Other examples include picking which armor to wear in a game and picking a font for text
in a word processor. The list of options should be ordered in some logical way to make scanning easier.
Picker views allow the user to:
● Quickly choose between a set of distinct options
Implementation: Date pickers are implemented in the UIDatePicker class and discussed in the UIDatePicker
Class Reference.
Configuring Picker Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Picker View Content Programmatically
Populating a picker requires both a data source and a delegate. It is not possible to populate a picker in Interface
Builder; you must do this programmatically.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
62
Picker Views
Picker views need a delegate to display data and appropriately handle user interaction. The delegate adopts
the UIPickerViewDelegate protocol and provides the content for each component’s row, either as an
attributed string, a plain string, or a view, and it typically responds to new selections or deselections. It also
implements methods to return the drawing rectangle for rows in each component—these optional methods
are only needed if the delegate returns a view as part of the picker’s content.
Additionally, picker views require a data source. The data source adopts the UIPickerViewDataSource
protocol and implements the required methods to return the number of components (columns) and the
number of rows in each component. Note that the actual contents of each row comes from the delegate, not
the data source.
For information about delegates and data sources, see “Delegates and Data Sources”.
After setting the data source and delegate, set the initial selection by calling the
selectRow:inComponent:animated: without animation. Typically this is done in a the viewDidLoad
method of the view’s view controller.
If the picker is visible, use animation when you update the selection.
You can dynamically change the rows of a component by calling the reloadComponent: method, or
dynamically change the rows of all components by calling the reloadAllComponents method. When you
call either of these methods, the picker view asks the delegate for new component and row data, and asks the
data source for new component and row counts. Reload a picker view when a selected value in one component
should change the set of values in another component. For example, changing a row value from February to
March in one component should change a related component representing the days of the month.
Specifying Picker View Behavior
You cannot customize the picker view’s selection indicator on iOS 7. The selection indicator is always shown,
so toggling the Shows Selection Indicator (showsSelectionIndicator) box has no effect.
Customizing Picker View Appearance
You cannot customize the appearance of picker views.
Using Auto Layout with Picker Views
You can create an Auto Layout constraint between a picker view and other user interface elements. You can
create any type of constraint for a picker view besides a baseline constraint.
Picker Views
Using Auto Layout with Picker Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
63
Picker views usually reside at the bottom of the screen in all device orientations. Select Bottom Space to
Superview and set the relation equal to 0 for the date picker to pin to the bottom of the screen in all device
orientations.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Picker Views Accessible
Picker views are accessible by default. The default accessibility trait for a picker view is Adjustable.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Picker Views
To internationalize picker view, you must provide localized translations of each string in the picker.
For more information, see Internationalization Programming Topics.
Debugging Picker Views
When debugging issues with picker views, watch for this common pitfall:
Not testing localizations. Be sure to test the pickers in your app with the localizations you intend to ship.
Elements Similar to a Picker View
The following elements provide similar functionality to a picker view:
● Date Picker. Uses a picker to let the user pick a date and time. For more information, see “Date
Pickers” (page 131).
● Stepper. Lets the user increment and decrement a value. For more information, see “Steppers” (page 156).
Picker Views
Making Picker Views Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
64
A progress view is used to illustrate the progress of a task over time in an app. You use a progress view to let
the user know how long until an operation completes, such as a download. The Mail app uses progress views
in several different situations, including when it’s downloading new messages or sending an outgoing message.
Progress views allow the user to:
● Receive feedback on a loading operation.
● See an estimate of how much time is left until a task finishes.
Implementation: Progress views are implemented in the UIProgressView class and discussed in the
UIProgressView Class Reference.
Configuring Progress Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
65
Progress Views
Setting Progress View Value
You can set the initial progress as a float between 0 and 1 by using the Progress (progress) field in the
Attributes Inspector. You can also do this programmatically using the setProgress:animated: method
without animation. This is typically done in the viewDidLoad method of the view controller.
If the progress view is visible, use animation when you update the progress.
Customizing Progress View Appearance
You can customize the appearance of a progress view by setting the properties depicted below.
To customize the appearance of all progress views in your app, use the appearance proxy (for example,
[UIProgressView appearance]). For more information about appearance proxies, see “Using Appearance
Proxies” (page 18).
Selecting Progress View Style
Progress Views
Configuring Progress Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
66
With progress views, you have two style options: default and bar. You can specify either value by using the
Style (progressViewStyle) field. There is no difference in functionality, only in appearance. The Default
style has blue-tinted progress and a gray track; the Bar style is a thinner version of the default.
Adjusting Progress View Tint
You can adjust the tint of two parts of the progress view: the track and the progress. The track tint applies to
the area of the track that is not filled, while the progress tint applies to the portion of the progress bar that is
filled. Use the Track Tint (trackTintColor) and Progress Tint (progressTintColor) fields to set custom
colors for the track and progress. You can adjust the tint for either style of the progress view.
Using Auto Layout with Progress Views
You can create Auto Layout constraints between a progress view and other user interface elements. You can
create any type of constraint for a progress view besides a baseline constraint.
To keep a progress view centered and adjust its width according to device orientation or screen size, you can
use Auto Layout to pin it to its superview. Using the Auto Layout Pin menu, create Leading Space to Superview
and Trailing Space to Superview constraints and set their values equal to each other. Doing this ensures that
the endpoints of your progress view are a specified distance from the edges of its superview. With these
constraints, the progress view stays centered and its width adjusts automatically for different device orientations
and screen sizes.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Progress Views
Using Auto Layout with Progress Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
67
Making Progress Views Accessible
Progress views are accessible by default. The default accessibility traits for a progress view are Updates Frequently
and User Interaction Enabled. The Updates Frequently accessibility trait means that the progress view doesn't
send update notifications when its state changes. This trait tells an assistive app that it should poll for changes
in the progress view when necessary.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Progress Views
Progress views have no special properties related to internationalization. However, if you use a progress view
with a label, make sure you provide localized strings for the label.
For more information, see Internationalization Programming Topics.
Elements Similar to a Progress View
The following element provides similar functionality to a progress view:
Activity Indicator View. For an indeterminate progress indicator—or, informally, a “spinner”—use an activity
indicator view. For more information, see “Activity Indicators” (page 26).
Progress Views
Making Progress Views Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
68
A scroll view allows users to see content that is larger than the scroll view’s boundaries. When a scroll view
first appears—or when users interact with it—vertical or horizontal scroll indicators flash briefly to show users
that there is more content they can reveal. Other than the transient scroll indicators, a scroll view has no
predefined appearance.
Scroll views allow the user to:
● View content that does not fit on the screen of the device
Implementation: Scroll views are implemented in the UIScrollView class and discussed in the UIScrollView
Class Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
69
Scroll Views
Configuring Scroll Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Scroll View Content
You set scroll view content programmatically by adding subviews to its content view with the addSubview:
method.
Specifying Scroll View Behavior
Scroll views need a delegate to handle scrolling, dragging, and zooming. By assigning a view controller as the
scroll view’s delegate and implementing any or all of the UIScrollViewDelegate methods, you can define
these behaviors.
Scroll Views
Configuring Scroll Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
70
A scroll view responds to the speed and direction of gestures to reveal content in a way that feels natural to
people. When users drag content in a scroll view, the content follows the touch; when users flick content, the
scroll view reveals the content quickly and stops scrolling when the user touches the screen or when the end
of the content is reached. A scroll view can also operate in paging mode, in which each drag or flick gesture
reveals one app-defined page of content.
Use the Shows Horizontal Scrollers (showsHorizontalScrollIndicator) and Shows Vertical Scrollers
(showsVerticalScrollIndicator) boxes to specify whether the corresponding scroll indicator should be
visible during tracking and fades out after tracking. These options are enabled by default; toggle off is you do
not want the scroller to be shown.
You can specify whether scrolling is enabled or disabled in the scroll view using the Scrolling Enabled
(scrollEnabled) checkbox. Scrolling is enabled by default. When scrolling is disabled, the scroll view does
not accept touch events; it forwards them up the responder chain.
If you check the Paging Enabled (pagingEnabled) box, the the scroll view stops on multiples of the scroll
view’s bounds when the user scrolls, giving the effect of scrolling through a single page at a time.
If you turn on directional lock by checking the Direction Lock Enabled (directionalLockEnabled) box, a
user will only be able to scroll in one direction at a time. By default, a user can scroll in both directions, or
diagonally.
If the Bounces Zoom (bouncesZoom) option is enabled, when zooming exceeds either the maximum or
minimum limits for scaling, the scroll view temporarily animates the content scaling just past these limits before
returning to them. If this option is disabled, zooming stops immediately at one a scaling limits.
Using the Delays Content Touches (delaysContentTouches) checkbox, you can specify whether the scroll
view delays the handling of touch-down gestures. When enabled, the view delays handling the touch-down
gesture until it can determine if scrolling is the intent.
Scroll Views
Configuring Scroll Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
71
You can indicate whether touches in the content view always lead to tracking by using the Cancellable Content
Touches (canCancelContentTouches) checkbox. When enabled, if a user drags their finger enough to initiate
a scroll within a view in the content that has begun tracking a finger touching it, that view receives a
touchesCancelled:withEvent: message and the scroll view handles the touch as a scroll. When disabled,
the scroll view does not scroll regardless of finger movement once the content view starts tracking.
Use the Bounces (bounces) checkbox to indicate whether the scroll view bounces past the edge of content
and back again. Enable Bounce Horizontally (alwaysBounceHorizontal) if you want content to bounce
when scrolled horizontally, and Bounce Vertically (alwaysBounceVertical) if you want content to bounce
when scrolled vertically.
You can use the Min Zoom (minimumZoomScale) and Max Zoom (maximumZoomScale) fields to specify how
much the scroll view’s content can be zoomed. The maximum zoom scale must be greater than the minimum
zoom scale for zooming to be enabled. The default value is 1.0.
Scroll Views
Configuring Scroll Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
72
Customizing Scroll View Appearance
You can customize the appearance of a scroll view by setting the properties depicted below.
To customize the appearance of all scroll views in your app, use the appearance proxy (for example,
[UIScrollView appearance]). For more information about appearance proxies, see “Using Appearance
Proxies” (page 18).
Setting Scroll View Style
The only way to customize the appearance of a scroll view is by setting the style of the scroll indicators. There
are three different choices for indicator style: default (black with a white border), white, or black. You can set
the indicator style using the “Style” (indicatorStyle) field in the Attributes Inspector.
Specifying Scroll View Content Layout
Scroll views have a number of options that dictate how their content is laid out. You specify the size of the
content using the contentSize property, which is initially set to zero. You can use the contentInset
property to specify a content inset, which is the distance that the content is padded or inset from the enclosing
scroll view. Additionally, you can use the contentOffset property or the setContentOffset:animated:
method to set the point at which the origin of the content view is offset from the origin of the scroll view.
Scroll Views
Configuring Scroll Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
73
Using Auto Layout with Scroll Views
You can create Auto Layout constraints between a scroll view and other user interface elements. You can create
any type of constraint for a scroll view besides a baseline constraint.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Scroll Views Accessible
Scroll views are accessible by default. The default accessibility trait for a scroll view is "User Interaction Enabled.”
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Scroll Views
For more information, see Internationalization Programming Topics.
Elements Similar to a Scroll View
The following elements provide similar functionality to a scroll view:
● Table View. A scrolling view that displays data items in a single-column list. For more information, see
“Table Views” (page 88).
● Collection View. A scrollable view that displays an ordered collection of data items using standard or
custom layouts. Similar to a table view, a collection view gets data from your custom data source objects
and displays it using a combination of cell, layout, and supplementary views. For more information, see
“Collection Views” (page 35).
Scroll Views
Using Auto Layout with Scroll Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
74
A search bar provides an interface for text-based searches with a text box and buttons such as search and
cancel. A search bar accepts text from users, which can be used as input for a search (shown here with
placeholder text). A scope bar, which is available only in conjunction with a search bar—allows users to define
the scope of a search (shown here below a search bar).
Search bars allow the user to:
● Quickly find a value in a large collection
● Create a scope filter
Implementation: Search bars are implemented in the UISearchBar class and discussed in the UISearchBar
Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
75
Search Bars
Configuring Search Bars
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Search Bars
Configuring Search Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
76
Setting Search Bar Content
The Text (text) field contains the current search text; you can use it to set an initial search. Don’t use it to
provide a description of the search; use placeholder text instead. Placeholder text is specified in the Placeholder
(placeholder) field, and is visible only when there is no other text in the search field. Placeholder text is
styled differently to communicate its different meaning to the user and it is automatically cleared when the
user starts typing. It is suitable for very short descriptions of what the user should enter in the search field.
The prompt text is specified in the Prompt (prompt) field. It appears directly above the search bar. Unlike the
placeholder text, the prompt text is visible whether or not the user has entered text in the search field, so it is
suitable for longer descriptions or directions.
Search bars can display a number of different buttons. The Cancel button is intended to terminate a search
operation; you can display this button by selecting the Shows Cancel Button checkbox. The Search Results and
Bookmarks buttons appear in the right side of search bar, and can be toggled to display those respective views.
You can display one of these buttons by selecting either the Shows Search Results Button
(showsSearchResultsButton) or Shows Bookmarks Button (showsBookmarkButton) checkbox. Note that
you cannot display both of these buttons simultaneously; if both properties are enabled, only the Search Results
button is visible.
Note: These buttons are merely user interface elements and have no functionality. You must
implement the appropriate functionality yourself using the corresponding UISearchBarDelegate
methods.
Search Bars
Configuring Search Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
77
A search bar can also display a scope bar, which lets users limit the scope of a search. For example, when
searching in an email app, the user could restrict the search to the Inbox or to a particular folder. To display a
scope bar, check the Shows Scope Bar (showsScopeBar) box and add an array of scope bar titles as strings
to the Scope Titles (scopeButtonTitles) field.
Specifying Search Bar Behavior
Search bars need a delegate to handle user interaction. You implement the UISearchBarDelegate protocol
on a delegate object to respond to user actions—for example, performing the search. Every search bar needs
a delegate object that implements the UISearchBarDelegate protocol. The delegate is responsible for
taking actions in response to user input such as editing the search text, starting or canceling a search, and
tapping in the scope bar. At the very minimum, the delegate needs to perform a search after text is entered
in the text field.
A user types content into a search bar using a keyboard, which has a number of customization options:
● Keyboard layout. The Keyboard field allows you to select from a number of different keyboard layouts.
Match the keyboard layout to the purpose and scope of the search bar. The default keyboard layout is an
alphanumeric keyboard in the device’s default language. For a list of possible keyboard types, see
UIKeyboardType.
● Capitalization scheme. The Capitalization field specifies how text should be capitalized in the search bar:
no capitalization, every word, every sentence, or every character. The no capitalization scheme is selected
by default.
● Auto-correction. The Correction field simply disables or enables auto-correct in the search bar.
Search Bars
Configuring Search Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
78
Customizing Search Bar Appearance
You can customize the appearance of a search bar by setting the following properties:
To customize the appearance of all search bars in your app, the appearance proxy (for example, [UISearchBar
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Specifying Search Bar Style
Bars have two standard appearance styles: translucent white with dark text (default) or translucent black with
light text. Use the Style (barStyle) field to select one of these standard styles.
Adjusting Search Bar Tint
You can specify a custom tint color for the search bar background using the Tint (barTintColor) field. The
default background tint color is white.
Additionally, you can set a custom tint color for the interactive elements within a search bar—including the
scope bar, cancel button, and cursor—programmatically using the tintColor property. The search bar will
inherit its superview’s tint color if a custom one is set, or show the default system blue color if none is set. For
more information, see “Adjusting View Tint Color” (page 19).
Search Bars
Configuring Search Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
79
Specifying Search Bar Background Images
A search bar can have a background image that covers the area behind the search field. Use the
backgroundImage property to set a background image for your search bar. You can also set the background
image for a search bar’s scope bar using the scopeBarBackgroundImage property. Single-pixel images or
stretchable images are stretched; otherwise, the image is tiled. If you set one of these background image
properties, you should also set the other to give your app interface a consistent look.
Setting Search Bar Translucency
Search bars are translucent by default on iOS 7. Additionally, there is a system blur applied to all search bars.
This allows your content to show through underneath the bar.
These settings automatically apply when you set any style for barStyle or any custom color for barTintColor.
If you prefer, you can make the search bar opaque by setting the translucent property to NO programmatically.
In this case, the bar draws an opaque background using black if the search bar has UIBarStyleBlack style,
white if the search bar has UIBarStyleDefault, or the search bar’s barTintColor if a custom value is
defined.
If the search bar has a custom background image, the default translucency is automatically inferred from the
average alpha values of the image. If the average alpha is less than 1.0, the search bar will be translucent by
default; if the average alpha is 1.0, the search bar will be opaque by default. If you set the translucent
property to YES on a search bar with an opaque custom background image, the search bar makes the image
translucent. If you set the translucent property to NO on a search bar with a translucent custom background
image, the search bar provides an opaque background for the image using black if the search bar has
UIBarStyleBlack style, white if the search bar has UIBarStyleDefault, or the search bar’s barTintColor
if a custom value is defined.
Specifying Search Bar Layout
You can also control certain aspects of the search bar’s layout by providing position adjustments: for icons
using the positionAdjustmentForSearchBarIcon: method, for the background image using the
searchFieldBackgroundPositionAdjustment property, and for search text using the
searchTextPositionAdjustment property.
Using Auto Layout with Search Bars
You can create Auto Layout constraints between a search bar and other user interface elements. You can create
any type of constraint for a search bar besides a baseline constraint.
Search Bars
Using Auto Layout with Search Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
80
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Search Bars Accessible
Search bars are accessible by default.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Search Bars
To internationalize a search bar, you must provide localized strings for the following properties:
● placeholder
● prompt
● text
● scopeButtonTitles
For more information, see Internationalization Programming Topics.
Debugging Navigation Bars
When debugging issues with navigation bars, watch for these common pitfalls:
● Specifying conflicting appearance settings. When customizing search bar appearance with a style or
color, use one option or the other, but not both. Conflicting settings for search bar appearance will be
resolved in favor of the most recently set value. For example, setting a new style clears any custom tint
color you have set. Similarly, setting a custom tint color overrides any style you have set.
● Performance issues. If search operations can be carried out very rapidly, it is possible to update the search
results as the user is typing by implementing the searchBar:textDidChange: method on the delegate
object. However, if a search operation takes more time, you should wait until the user taps the Search
button before beginning the search in the searchBarSearchButtonClicked: method. Always perform
search operations a background thread to avoid blocking the main thread. This keeps your app responsive
to the user while the search is running and provides a better user experience.
Search Bars
Making Search Bars Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
81
Elements Similar to a Search Bar
The following element provides similar functionality to a search bar:
Toolbar. A toolbar object contains controls that allow the user to perform actions related to objects onscreen.
For more information, see “Toolbars” (page 104).
Search Bars
Elements Similar to a Search Bar
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
82
A tab bar provides easy access to different views in an app. Use a tab bar to organize information in your app
by subtask. The most common way to use a tab bar is with a tab bar controller. You can also use a tab bar as
a standalone object in your app.
Tab bars allow the user to:
● Quickly navigate within an app
● Get an understanding of the app’s layout
Implementation:
● Tab bars are implemented in the UITabBar class and discussed in the UITabBar Class Reference.
● Tab bar items are implemented in the UITabBarItem class and discussed in the UITabBarItem Class
Reference.
Configuring Tab Bars
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
83
Tab Bars
Specifying Tab Bar Content
Each tab on a tab bar is represented as a UITabBarItem, and you use the UITabBarItem class methods to
create a tab bar item. Each tab bar item has a title, selected image, unselected image, and a badge value.
After you create your tab bar items, add them to your tab bar with the items property, which is an array of
UITabBarItem objects. If you want to animate changes to your tab bar items array, use the
setItems:animated: method instead.
Specifying Tab Bar Behavior
You can change the contents of a tab bar at runtime, and allow users to add, remove, or reorder tabs. To present
a modal view that allows users to customize a tab bar, use the beginCustomizingItems: method. You can
also add a UITabBarDelegate object to your app. The tab bar delegate receives messages when the user
customizes the tab bar.
The most common way to use a tab bar is in conjunction with a tab bar controller. A UITabBarController
object manages the various tab views and view controllers, and the tab bar itself. If you use a tab bar controller,
you should not use the UITabBar methods or properties to modify the tab bar. If you do, the system throws
an exception. For more information about how to create a tab bar interface with an associated tab bar controller,
see “Tab Bar Controllers”.
Customizing Tab Bar Appearance
You can customize the appearance of a tab bar by setting the properties depicted below.
To customize the appearance of all tab bars in your app, use the appearance proxy (for example, [UITabBar
appearance]). For more information, see “Using Appearance Proxies” (page 18).
Specifying Tab Bar Style
Tab bars have two standard appearance styles: translucent white with dark text (default) or translucent black
with light text. Use the barStyle property to programmatically select one of these standard styles.
Tab Bars
Configuring Tab Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
84
Adjusting Tab Bar Tint
You can specify a custom tint color for the bar background using the Tint (barTintColor) field. The default
background tint color is white.
Use the Image Tint (selectedImageTintColor) field to specify the bar item’s tint color when that tab is
selected. By default, that color is blue.
Setting Tab Bar Images
The selection indicator image is shown when a tab is selected. It is drawn on top of the tab bar, behind the
bar item icon. By default, there is no selection indicator image, but you can set a custom one using the
selectionIndicatorImage property.
By default, there is no divider image between tabs on a tab bar. You can set custom divider images for each
combination of left and right tab control states using the setDividerImage:forLeftState:rightState:
method. If you use custom dividers, make sure to set divider images all combinations of tabs states: left selected,
right selected, or both unselected.
You can also set a custom background image for your entire tab bar using the backgroundImage property.
If you set this property with a stretchable image, the image is stretched. If you use a non-stretchable image,
the image is tiled.
If you want to use custom shadow image for the tab bar, set the shadowImage property. To show a custom
shadow image, you must also set a custom background image with backgroundImage.
Setting Tab Bar Translucency
Tab bars are translucent by default on iOS 7. Additionally, there is a system blur applied to all tab bars. This
allows your content to show through underneath the bar.
These settings automatically apply when you set any style for barStyle or any custom color for barTintColor.
If you prefer, you can make the tab bar opaque by setting the translucent property to NO programmatically.
In this case, the bar draws an opaque background using black if the tab bar has UIBarStyleBlack style,
white if the tab bar has UIBarStyleDefault, or the tab bar’s barTintColor if a custom value is defined.
If the tab bar has a custom background image, the default translucency is automatically inferred from the
average alpha values of the image. If the average alpha is less than 1.0, the tab bar will be translucent by
default; if the average alpha is 1.0, the tab bar will be opaque by default. If you set the translucent property
to YES on a tab bar with an opaque custom background image, the tab bar makes the image translucent. If
Tab Bars
Configuring Tab Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
85
you set the translucent property to NO on a tab bar with a translucent custom background image, the tab
bar provides an opaque background for the image using black if the tab bar has UIBarStyleBlack style,
white if the tab bar has UIBarStyleDefault, or the tab bar’s barTintColor if a custom value is defined.
Setting Tab Bar Item Glyphs
Each item in a tab bar can have a custom selected image and unselected image. You can specify these images
when you initialize a tab bar item using the initWithTitle:image:selectedImage: method. Note that
a tab bar item image will be automatically rendered as a template image within a tab bar, unless you explicitly
set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using
Template Images” (page 19).
Using Auto Layout with Tab Bars
You can create Auto Layout constraints between a tab bar and other user interface elements. You can create
any type of constraint for a tab bar besides a baseline constraint.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Tab Bars Accessible
Tab bars are accessible by default.
With VoiceOver enabled on an iOS device, when a user touches a tab in a tab bar, VoiceOver reads the title of
the tab, its position in the bar, and whether it is selected. For example in the iTunes app on iPad, you might
hear “Selected, Audiobooks, four of seven” or “Genius, six of seven.”
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Tab Bars
To internationalize a tab bar, you must provide localized strings for the tab bar item titles.
For more information, see Internationalization Programming Topics.
Tab Bars
Using Auto Layout with Tab Bars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
86
Elements Similar to a Tab Bar
The following classes provide similar functionality to a tab bar:
● Segmented Control. Similar to a tab bar, a segmented control functions as a button that shows different
views. If you want to provide functionality similar to a tab bar, but don’t want those controls to be persistent,
consider using a segmented control. Remember that a tab bar should be accessible from every location
in an app. For more information, see “Segmented Controls” (page 142).
● Navigation Bar. A navigation bar also allows users to navigate through different content views, but it
offers a linear path. With a tab bar, a user can view any other tab at any given time. For more information,
see “Navigation Bars” (page 55).
● Toolbar. Both a tab bar and a toolbar are always visible onscreen. However, unlike a tab bar, which switches
between views, a UIToolbar object contains controls that allow the user to perform actions related to
objects onscreen. For more information, see “Toolbars” (page 104).
Tab Bars
Elements Similar to a Tab Bar
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
87
A table view presents data in a scrollable list of multiple rows that may be divided into sections. It presents
data in a single-column list of multiple rows and is a means for displaying and editing hierarchical lists of
information. For instance, the Mail application uses a table view to display email messages in a user’s inbox.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
88
Table Views
In normal mode, selecting a message allows the user to read it. In editing mode, selecting a message allows
the user to delete it from the inbox. Table views provide a simple yet versatile interface for managing and
interacting with collections of data.
Table views allow the user to:
Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
89
● Navigate through hierarchically structured data
● View an indexed list of items
● See detail information and controls in visually distinct groupings
● Interact with a selectable list of options
Implementation:
● Table views are implemented in the UITableView class and discussed in UITableView Class Reference.
● Individual table cells are implemented in the UITableViewCell class and discussed in UITableViewCell
Class Reference.
● Table headers and footers are implemented in the UITableViewHeaderFooterView class and discussed
in UITableViewHeaderFooterView Class Reference.
Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
90
Configuring Table Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Table Views
Configuring Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
91
Setting Table Content
To display content, a table view must have a data source. The data source mediates between the app’s data
model and the table view. A table view’s data source must conform to the UITableViewDataSource protocol.
For more information about the data source, see “Data Source and Delegate” in Table View Programming Guide
for iOS.
Each individual table cell can display a variety of content. Cells that use the default basic style can display an
image and text label, and cells that use one of the other three standard styles can display an image, text label,
and detail text label in a particular pre-defined layout. You can set a cell’s image programmatically using the
“Image” (image) field in the Attributes Inspector, which appears when the cell is in one of the four standard
styles. However, you must set the textLabel and detailTextLabel properties programmatically. To learn
more about table cell content, see “A Closer Look at Table View Cells”.
A cell’s content—image, text, and any custom views—resides in its content view. If you want to customize
your table cell beyond the standard cell styles, you can set the cell style to custom and add your custom views
to the cell’s contentView property programmatically.
Each table—and each section within that table—can have a header and a footer that displays text or custom
content. You use headers and footers to display additional information about the table or its sections. The
UITableViewHeaderFooterView class implements a reusable view that you can place at the top or bottom
of a table or table section.
Headers and footers can either display a text label and optional detail text label, or custom content. You can
set the textLabel and detailTextLabel properties programmatically. Alternatively, you can add your
custom views to the header or footer’s contentView property programmatically. If you are using any custom
content in a header or footer, do not use the standard textLabel and detailTextLabel properties; instead,
add your own labels to the content view. For more information about headers and footers, see “Grouped Table
Views” in Table View Programming Guide for iOS and UITableViewHeaderFooterView Class Reference.
Table Views
Configuring Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
92
Specifying Table View Behavior
Table views need a delegate to manages the appearance and behavior. By assigning a view controller as the
table view’s delegate and implementing any or all of the UITableViewDelegate methods, you can allow
the delegate to manage selections, configure section headings and footers, help to delete and reorder cells,
and perform other actions.
Table selection style controls the number of cells a user can select at a given time. There are three types of
selection available for individual cells in a table view: single, multiple, or none. Tables can have different types
of selection in normal mode and editing mode. For example, you can allow users to select multiple items in
normal mode, but only delete one item at a time in editing mode. In Interface Builder, you can specify selection
style for normal mode using the Selection field, and for editing mode using the Editing field. You can also
choose whether a cell is visually highlighted upon selection by checking the Show Selection on Touch box.
Index Row Limit (sectionIndexMinimumDisplayRowCount) allows you to specify the minimum number
of rows required in the table for the index to be shown. Note that this applies to plain style tables only.
A reuse identifier is a string used to identify a cell that can be reused for multiple rows of a table view (for
performance purposes). You can set this property using the Identifier (reuseIdentifier) field in the Attributes
Inspector. You can also set a reuse identifier programmatically during cell initialization.
You can set indentation values for cell content through the Level (indentationLevel) and Width
(indentationWidth) fields. The width is the value for each level of indentation. You can indicate whether to
indent cell content in editing mode by checking the Indent While Editing (shouldIndentWhileEditing)
box.
Table Views
Configuring Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
93
Checking the Shows Re-order Controls (showsReorderControl) box will cause the cell to display a control
that allows it to be reordered within the table in editing mode. However, you must also implement the
UITableViewDataSource method tableView:moveRowAtIndexPath:toIndexPath: and set
tableView:canMoveRowAtIndexPath: to return YES to get the reordering control to appear in a particular
cell. This part must be done programmatically.
To make the table view aware of a header or footer view, you need to register it. You do this using the
registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method.
Similar to that of a table cell, the header or footer’s reuse identifier is a string used to identify a header or footer
view that can be reused for multiple headers or footers within a table. It is set during initialization using the
initWithReuseIdentifier: method.
Table Views
Configuring Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
94
Customizing Table View Appearance
You can customize the appearance of a table view by setting the properties depicted below.
To customize the appearance of all table views in your app, use the appearance proxy (for example,
[UITableView appearance]). For more information about appearance proxies, see “Using Appearance
Proxies” (page 18).
Specifying Table View Style
Table Views
Configuring Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
95
Separator style dictates how a table’s cells are separated visually. You can customize the style and color of
table cell separators using the Separator (separatorStyle, separatorColor) fields in the Attributes
Inspector. There are three available styles: single line, etched line, or none.
Table style affects the appearance of a table’s sections. Tables have two styles: plain and grouped. Certain
appearance properties only apply when a table view is displayed in one particular style. You can select the
style of a table to be plain or grouped using the Style (style) attribute.
Setting Cell Selection Style
Cell selection style specifies which color the outline of a selected cell will appear: gray, blue, or none. Use the
Selection (selectionStyle) field to set cell selection style.
Choosing Accessory Types
You can also set accessory types for normal and editing modes through the Accessory (accessoryType) and
Editing Acc. (editingAccessoryType) fields in the Attributes Inspector. For a list of standard accessory types,
see Cell Accessory Type.
Alternatively, you can use custom views by setting the accessoryView and editingAccessoryView
properties programmatically. Custom views have precedence over the standard accessory types, so if you set
the accessory view properties, your cell ignores the value of the accessoryType and editingAccessoryType
properties.
Specifying Cell Layout
The cell style attribute determines how content is visually laid out in a cell. You can select one of four existing
styles—or create a custom one—in the Style field of a table cell’s Attributes Inspector.
Table Views
Configuring Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
96
Specifying Header and Footer Appearance
You can customize the appearance of your header or footer by setting a custom background view or tint color.
The background view is placed behind the contentView and used to display static background content
behind the header or footer. For example, you might assign an image view to this property and use it to display
a custom background image. Alternatively, you can set a custom tint for the header or footer view by setting
its tintColor property. Avoid setting both a custom background view and a custom tint.
Using Auto Layout with Table Views
You can create Auto Layout constraints between a table view and other user interface elements. You can create
any type of constraint for a table view besides a baseline constraint.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Table Views Accessible
Table views are accessible by default. Accessibility for tables is handled at the table cell level.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Table Views
To internationalize a table view, you must provide localized strings for text labels and detail text labels of all
table cells, headers, and footers.
For more information, see Internationalization Programming Topics.
Elements Similar to a Table View
The following element provides similar functionality to a table view:
Scroll View. A class that provides support for displaying content that is larger than the size of the app’s window.
Use this class when your app contains too much information to display on an iOS device screen at one time.
For more information, see “Scroll Views” (page 69).
Table Views
Using Auto Layout with Table Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
97
A text view accepts and displays multiple lines of text. Text views support scrolling and text editing. You
typically use a text view to display a large amount of text, such as the body of an email message.
Text views allow the user to:
● Input user content into an app
Implementation: Text views are implemented in the UITextView class and discussed in the UITextView Class
Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
98
Text Views
Configuring Text Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Text View Content
Set text view content using the Text (text and attributedText) field. Both properties get set whether you
specified the value of the field to be plain or attributed. Plain text supports a single set of formatting
attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports
multiple sets of attributes that apply to individual characters or ranges of characters in the string.
Text Views
Configuring Text Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
99
Specifying Text View Behavior
By default, users can add, remove, or change text within a text view. To disable these behaviors, uncheck the
Editable (editable) checkbox in the Attributes Inspector.
A text view is capable of recognizing when text is formatted as a link, address, phone number, or event. If you
enable the corresponding Detection (dataDetectorTypes) checkboxes, users will be able to trigger the
appropriate action for each type of text by clicking it in the text view. For example, they will be able to call a
phone number or add an event to their calendar.
A user types content into a text view using a keyboard, which has a number of customization options:
● Keyboard layout. The Keyboard field allows you to select from a number of different keyboard layouts.
Match the keyboard layout to the purpose of the text view. If the user will be entering a web address,
select the URL keyboard. The default keyboard layout is an alphanumeric keyboard in the device’s default
language. For a list of possible keyboard types, see UIKeyboardType. You cannot customize the appearance
of the keyboard on iOS 7.
● Return key. The return key, which appears in the bottom right of the keyboard, allows the user to notify
the system when they are finished editing the text field. You can select one of several standard return key
types by using the Return Key field. The return key is disabled by default, and only becomes enabled when
a user types something into the text view. If you want your user to be able to press the return key any
Text Views
Configuring Text Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
100
time the keyboard is open, even if the input is empty or incomplete, you can select the Auto-enable Return
Key checkbox. Different return keys are intended to provide the user with an understanding of what action
hitting the key will trigger. Note that simply selecting a different return key appearance does not provide
you with the functionality intended by that key; you must implement the action yourself. Unlike text field
delegates, a text view delegate does not provide a method that gets called when the return key is pressed.
However, you can implement custom return key functionality in the text view delegate’s
textView:shouldChangeTextInRange:replacementText: method, which gets called after every
keystroke.
● Capitalization scheme. The Capitalization field specifies how text should be capitalized in the text view:
no capitalization, every word, every sentence, or every character. The sentence capitalization scheme is
selected by default.
● Auto-correction. The Correction field simply disables or enables auto-correct in the text view.
● Secure content. The Secure checkbox is unselected by default. Selecting it causes the text view to obscure
text once it is typed, allowing the user to safely enter secure content—such as a password—into the view.
You can use the text view delegate methods to handle custom keyboard dismissal.
Customizing Text View Appearance
You can customize the appearance of a text view by setting the properties depicted below.
To customize the appearance of all text views in your app, use the appearance proxy (for example, [UITextView
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Specifying Text Appearance
Text views can have one of two types of text: plain or attributed. Plain text supports a single set of formatting
attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports
multiple sets of attributes that apply to individual characters or ranges of characters in the string.
Text Views
Configuring Text Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
101
Using Auto Layout with Text Views
You can create Auto Layout constraints between a text view and other user interface elements. You can create
any type of constraint for a text view besides a baseline constraint.
You generally want the text view to fill the full width of your screen. To ensure that this happens correctly on
all devices and orientations, you can create “Leading Space to Superview” and “Trailing Space to Superview”
constraints, and set both values equal to 0. This will ensure that the text view remains pinned to the edges of
the device screen.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Text Views Accessible
Text views are accessible by default. The default accessibility trait for a text view is User Interaction Enabled.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Text Views
For more information, see Internationalization Programming Topics.
Debugging Text Views
When debugging issues with text views, watch for this common pitfall:
Text Views
Using Auto Layout with Text Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
102
Placing a text view inside of a scroll view. Text views handle their own scrolling. You should not embed text
view objects in scroll views. If you do so, unexpected behavior can result because touch events for the two
objects can be mixed up and wrongly handled.
Elements Similar to a Text View
The following element provides similar functionality to a text view:
Scroll View. Use a scroll view for scrollable content. For more information, see “Scroll Views” (page 69).
Text Views
Elements Similar to a Text View
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
103
A toolbar usually appears at the bottom of a screen, and displays one or more buttons called toolbar items.
Generally, these buttons provide some sort of tool that is relevant to the screen’s current content. A toolbar
is often used in conjunction with a navigation controller, which manages both the navigation bar and the
toolbar.
Toolbars allow the user to:
● Select one of a set of performable actions within a given view
Implementation:
● Toolbars are implemented in the UIToolbar class and discussed in UIToolbar Class Reference.
● Bar button items are implemented in the UIBarButtonItem class and discussed in UIBarButtonItem Class
Reference.
● Bar items are implemented in the UIBarItem class and discussed in UIBarItem Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
104
Toolbars
Configuring Toolbars
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Toolbar Content
After you create a toolbar, you need to add items to the bar. Each item is a UIBarButtonItem object, which
you can add to the toolbar directly in Interface Builder or in code using the items property. If you want to
animate changes to your toolbar items array, use the setItems:animated: method.
Toolbars
Configuring Toolbars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
105
You can specify the content of a particular bar button item by selecting its identifier. The identifier can either
be custom or take on the value of well-know system buttons such as Edit or Done. For a list of system identifiers,
see UIBarButtonSystemItem.
If you are using a bar button item with the custom identifier, you can set some of its properties at the UIBarItem
level. For example, you can specify either a custom title or image using the Title (title) or Image (image)
fields.
You can assign a tag to your bar button item using the Tag (tag) field. This is intended to be a unique identifier
for your button so you can access it in code.
Specifying Toolbar Behavior
Toolbars do not need a delegate to function properly; their parent view controller can define their behavior
without implementing any delegate protocols.
When a user clicks a particular button on the toolbar, you can respond by performing some corresponding
action in your app, such as deleting an email. You register the target-action method for a bar button item as
shown below.
self.myBarButtonItem.target = self;
self.myBarButtonItem.action = @selector(myAction:);
Alternatively, you can Control-drag the bar button item’s selector from the Connections Inspector to the action
method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
Toolbars
Configuring Toolbars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
106
You can disable or enable a given button on the toolbar by selecting the button in Interface Builder and
toggling its Enabled (enabled) box.
A common way to create and manage a toolbar is in conjunction with a navigation controller. The navigation
controller displays the toolbar and populates it with items from the currently visible view controller. Using a
navigation controller is ideal for an app design where you want to change the contents of the toolbar
dynamically. However, you should not use a navigation controller if your app does not have or need a navigation
bar. For more information, see “Displaying a Navigation Toolbar” in View Controller Catalog for iOS.
Customizing Toolbar Appearance
You can customize the appearance of a toolbar by setting the properties depicted below.
To customize the appearance of all toolbars in your app, use the appearance proxy (for example, [UIToolbar
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Toolbars
Configuring Toolbars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
107
Specifying Toolbar Style
Toolbar have two standard appearance styles: translucent white with dark text (default) or translucent black
with light text. Use the Style (barStyle) field to select one of these standard styles.
Adjusting Toolbar Tint
You can specify a custom tint color for the bar background using the Tint (barTintColor) field. The default
background tint color is white.
Additionally, you can set a custom tint color for the interactive elements within a toolbar bar—including the
button images and text—programmatically using the tintColor property. The toolbar bar will inherit its
superview’s tint color if a custom one is set, or show the default system blue color if none is set. For more
information, see “Adjusting View Tint Color” (page 19).
Setting Toolbar Background Images
You can set a custom background image for your toolbar using the
backgroundImageForToolbarPosition:barMetrics: method. The image must be the correct dimensions
in order to cover the area of the toolbar correctly. Remember to set custom images for different sets of bar
metrics.
If you want to use custom shadow image for the toolbar, use the setShadowImage:forToolbarPosition:
method. To show a custom shadow image, you must also set a custom background image with
backgroundImageForToolbarPosition:barMetrics:.
Setting Toolbar Translucency
Toolbars are translucent by default on iOS 7. Additionally, there is a system blur applied to all toolbars. This
allows your content to show through underneath the bar.
Toolbars
Configuring Toolbars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
108
These settings automatically apply when you set any style for barStyle or any custom color for barTintColor.
If you prefer, you can make the toolbar opaque by setting the translucent property to NO programmatically.
In this case, the bar draws an opaque background using black if the toolbar has UIBarStyleBlack style,
white if the toolbar has UIBarStyleDefault, or the toolbar’s barTintColor if a custom value is defined.
If the toolbar has a custom background image, the default translucency is automatically inferred from the
average alpha values of the image. If the average alpha is less than 1.0, the toolbar will be translucent by
default; if the average alpha is 1.0, the toolbar will be opaque by default. If you set the translucent property
to YES on a toolbar with an opaque custom background image, the toolbar makes the image translucent. If
you set the translucent property to NO on a toolbar with a translucent custom background image, the
toolbar provides an opaque background for the image using black if the toolbar has UIBarStyleBlack style,
white if the toolbar has UIBarStyleDefault, or the toolbar’s barTintColor if a custom value is defined.
Setting Bar Button Item Glyphs
Any bar button in a toolbar can have a custom image instead of text. You can provide this image to your bar
button item during initialization. Note that a bar button image will be automatically rendered as a template
image within a toolbar, unless you explicitly set its rendering mode to
UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19).
Using Auto Layout with Toolbars
You can create Auto Layout constraints between a toolbar and other user interface elements. You can create
any type of constraint for a toolbar besides a baseline constraint.
You cannot create Auto Layout constraints for individual bar button items. However, you can use bar button
items with the Fixed Space and Flexible Space identifiers to determine the spacing of buttons on your toolbar.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Toolbars Accessible
Toolbars are accessible by default.
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Toolbars
Using Auto Layout with Toolbars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
109
Internationalizing Toolbars
To internationalize a toolbar, you must provide localized strings for all button titles. Remember to test all
localizations, as button size may change unexpectedly when using localized strings.
For more information, see Internationalization Programming Topics.
Debugging Toolbars
When debugging issues with toolbars, watch for this common pitfall:
Trying to customize the content of a non-custom bar button item. If you try to set a custom title or image—at
the UIBarItem level—for a bar button item with a non-custom identifier, the bar button item’s identifier will
automatically switch to the custom type in Interface Builder.
Elements Similar to a Toolbar
The following elements provide similar functionality to a toolbar:
● Tab Bar. A toolbar is most similar to a tab bar—both can appear at the bottom of the screen. Use a toolbar
to display controls that perform specific functions, and use a tab bar to allow the user to switch between
different views or subtasks. For more information, see “Tab Bars” (page 83).
● Navigation Bar. For more information, see “Navigation Bars” (page 55).
Toolbars
Internationalizing Toolbars
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
110
A web view is a region that can display rich HTML content (shown here between the navigation bar and toolbar
in Mail on iPhone).
Web views allow the user to:
● View web content within an app
Implementation: Web views are implemented in the UIWebView class and discussed in the UIWebView Class
Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
111
Web Views
Configuring Web Views
Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Web View Content Programmatically
To get your web view to display content, you simply create a UIWebView object, attach it to a window, and
send it a request to load web content. Use the loadRequest: method to begin loading web content, the
stopLoading method to stop loading, and the loading property to find out if a web view is in the process
of loading. You can create the web view object in code or in Interface Builder, but you can load content in
code only.
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:@"http://www.apple.com/"]]];
Specifying Web View Behavior
You can set your web view to automatically scale web content to fit on the screen of the user’s device. By
default, this behavior is disabled, but you can enable it by checking the Scales Page To Fit (scalesPageToFit)
box in Attributes Inspector. Enabling this property also allows the user to zoom in and out in the web view.
Web Views
Configuring Web Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
112
A web view is capable of recognizing when web text is formatted as a link, address, phone number, or event.
If you enable the corresponding Detection (dataDetectorTypes) checkboxes, users will be able to trigger
the appropriate action for each type of text by clicking it in the web view. For example, they will be able to
call a phone number or add an event to their calendar.
Customizing Web View Appearance
You cannot customize the appearance of a web view.
Using Auto Layout with Web Views
You can create Auto Layout constraints between a web view and other user interface elements. You can create
any type of constraint for a web view besides a baseline constraint.
You generally want the web view to fill the full width of your screen. To ensure that this happens correctly on
all devices and orientations, you can create “Leading Space to Superview” and “Trailing Space to Superview”
constraints, and set both values equal to 0. This will ensure that the web view remains pinned to the edges of
the device screen.
For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page
20).
Making Web Views Accessible
Web views are accessible by default. The default accessibility trait for a web view is "User Interaction Enabled.”
For general information about making iOS views accessible, see “Making Views Accessible” (page 21).
Internationalizing Web Views
Web views have no special properties related to internationalization.
For more information, see Internationalization Programming Topics.
Debugging Web Views
When debugging issues with web views, watch for these common pitfalls:
Web Views
Using Auto Layout with Web Views
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
113
● Placing a web view inside of a scroll view. Web views handle their own scrolling. You should not embed
web view objects in scroll views. If you do so, unexpected behavior can result because touch events for
the two objects can be mixed up and wrongly handled.
● Not testing web content size. Web content comes in a variety of sizes, and it may be difficult to view
content that is too large or too small for a device screen. Enable the scalesPageToFit property to allow
users to zoom in or out if you anticipate that this might be the case for your app.
● Not having a valid Internet connection. Since web views rely entirely on the Internet, a working connection
is essential to loading web view content. Slow or disabled connections may make it appear as if your web
view is not functioning properly when the actual problem is with the connection.
Elements Similar to a Web View
The following element provides similar functionality to a web view:
Scroll View. Use a scroll view for scrollable content. For more information, see “Scroll Views” (page 69).
Web Views
Elements Similar to a Web View
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
114
● “About Controls” (page 116)
● “Buttons” (page 123)
● “Date Pickers” (page 131)
● “Page Controls” (page 137)
● “Segmented Controls” (page 142)
● “Text Fields” (page 165)
● “Sliders” (page 149)
● “Steppers” (page 156)
● “Switches” (page 161)
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
115
Controls
Important: This is a preliminary document for an API or technology in development. Although this document
has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only
by registered members of the applicable Apple Developer program. Apple is supplying this confidential
information to help you plan for the adoption of the technologies and programming interfaces described
herein. This information is subject to change, and software implemented according to this document should
be tested with final operating system software and final documentation. Newer versions of this document
may be provided with future seeds of the API or technology.
A control is a communication tool between a user and an app. The user interacts with a control to convey a
particular action or intention to the app. Controls can be used to manipulate content, provide user input,
navigate within an app, or execute other pre-defined actions.
Controls are simple, straightforward, and familiar to users because the appear throughout many iOS apps. The
UIControl class is the base class for all controls on iOS, and defines the functionality that is common to all
controls. You should never use it directly; instead, use one of its subclasses. Each subclass of UIControl defines
appearance, behavior, and intended usage specific to that particular control. By using controls carefully and
consistently in your app, you can convey to users what they have the freedom and ability to do within the app.
Controls allow the user to:
● Interact with an app.
● Manipulate or edit app content.
● Convey user intent to the app in a straightforward way.
Implementation: Controls are implemented in the UIControl class and discussed in UIControl Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
116
About Controls
Configuring Controls
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. Each field in the Attributes Inspector that corresponds to a
particular API property lists it in parentheses. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Control Content
Each subclass of UIControl has different content or values that you can set. To learn about setting content
for a particular control, read its corresponding chapter:
● Buttons
● Date Pickers
● Page Controls
● Segmented Controls
● Text Fields
● Sliders
● Steppers
● Switches
Specifying Control Behavior
Understanding Control States
A control state describes the current interactive state of a control: normal, selected, enabled, or highlighted.
A control can have more than one state at a time, and you can change a control’s state at any point. For a full
listing of control states, see UIControlState.
About Controls
Configuring Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
117
When a user interacts with a control, the control’s state changes appropriately. You can configure controls to
have different appearances for different states to provide users with feedback about which state the control
is in. For example, you might configure a button to display one image when it is in its normal state and a
different image when it is highlighted.
The fastest way to configure the initial state of a control is by using the Attributes Inspector:
When a control is enabled, a user can interact with it. When a control is disabled, it appears grayed out and
does not respond to user interaction. Controls are enabled by default; to disable a control, uncheck the “Enabled”
(enabled) box in the Attributes Inspector.
A control enters a temporary highlighted state when when a touch enters and exits during tracking and when
there is a touch up event. A highlighted state is temporary. You can customize the highlighted appearance of
some controls, such as buttons. Controls are not highlighted by default; to set a control’s initial state to
highlighted, check the “Highlighted” (highlighted) box in the Attributes Inspector.
When a user taps on a control, the control enters the selected state. For many controls, this state has no effect
on behavior or appearance. However, some subclasses may have different appearance depending on their
selected state. For example, UISegmentedControl segments have a distinctly different appearance when
selected. You can set a control to be selected using the “Selected” (selected) checkbox.
Understanding Control Events
A control event represents various physical gestures that users can make on controls, such as lifting a finger
from a control, dragging a finger into a control, and touching down within a text field. For a full listing of
control events, see UIControlEvents.
Understanding the Target-Action Mechanism
The target-action mechanism is a model for configuring a control to send an action message to a target object
after a specific control event. For example, when a user interacts with a slider, it generates a
UIControlEventValueChanged control event. You could use this event to update a label’s text to the current
value of the slider. In this case, the sender is the slider, the control event is Value Changed, the action is updating
the label’s text, and the target is the controller file containing the label as an IBOutlet.
To create a relationship between the slider, the control event, the target, and the action, you can do one of
two things:
1. Call the addTarget:action:forControlEvents: method within your target file:
About Controls
Configuring Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
118
[self.mySlider addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
2. Use the Connections Inspector in Interface Builder to Control-drag the slider’s Value Changed event to
the action method in the target file.
3. Control-click the slider in Interface Builder, and drag its Value Changed event to the target object in your
Storyboard. Select the appropriate action from the list of actions available for the target.
For more information, see “Target-Action in UIKit” in Cocoa Fundamentals Guide
Customizing Control Appearance
Adjusting Control Content Alignment
Certain controls—such as buttons and text fields—can contain custom images or text. For these controls, you
can specify the alignment of that content by using the “Horizontal Alignment”
(contentHorizontalAlignment) and “Vertical Alignment” (contentVerticalAlignment) options in
Attributes Inspector. Using the horizontal alignment options, you can specify whether the content appears
aligned with the left, center, or right of the control, or whether it fills the width of the control. Using the vertical
alignment options, you can specify whether the content appears aligned with the top, center, or bottom of
the control, or whether it fills the height of the control. This is a great tool for ensuring your content appears
exactly where you want it to within your control (for example, centering text in a text field).
About Controls
Configuring Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
119
Note: These alignment options apply to the content of a control, not the control itself. For information
about aligning controls with respect to other controls or views, see “Using Auto Layout with
Controls” (page 120).
Using Auto Layout with Controls
The auto layout system allows you to define layout constraints for user interface elements, such as views and
controls. Constraints represent relationships between user interface elements. You can create auto layout
constraints by selecting the appropriate element or group of elements and selecting an option from the menu
in the bottom right corner of Xcode’s Interface Builder.
Auto layout contains two menus of constraints: pin and align. The Pin menu allows you to specify constraints
that define some relationship based on a particular value or range of values. Some apply to the control itself
(width) while others define relationships between elements (horizontal spacing). The following tables describes
what each group of constraints in the auto layout menu accomplishes:
PurposeConstraint Name
Sets the width or height of a single element.
Sets the horizontal or vertical spacing between exactly two elements.
Sets the spacing from one or more elements to the leading, trailing, top,
or bottom of their container view. Leading and trailing are the same as
left and right in English, but the UI flips when localized in a right-to-left
environment.
Sets the widths or heights of two or more elements equal to each other.
Aligns the left, right, top, or bottom edges of two or more elements.
Aligns two or more elements according to their horizontal centers, vertical
centers, or bottom baselines. Note that baselines are different from bottom
edges. These values may not be defined for certain elements.
Aligns the horizontal or vertical centers of one or more elements with
the horizontal or vertical center of their container view.
About Controls
Using Auto Layout with Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
120
The “Constant” value specified for any Pin constraints (besides Widths/Heights Equally) can be part of a
“Relation.” That is, you can specify whether you want the value of that constraint to be equal to, less than or
equal to, or greater than or equal to the value.
For more information, see Cocoa Auto Layout Guide.
Making Controls Accessible
Controls are accessible by default. To be useful, an accessible user interface element must provide accurate
and helpful information about its screen position, name, behavior, value, and type. This is the information
VoiceOver speaks to users. Visually impaired users can rely on VoiceOver to help them use their devices.
The iOS SDK contains a programming interface and tools that help you ensure that the user interface elements
in your application are both accessible and useful. The UI Accessibility programming interface defines the
following attributes:
● Label. A short, localized word or phrase that succinctly describes the control or view, but does not identify
the element’s type. Examples are “Add” or “Play.”
● Traits. A combination of one or more individual traits, each of which describes a single aspect of an
element’s state, behavior, or usage. For example, an element that behaves like a keyboard key and that
is currently selected can be characterized by the combination of the Keyboard Key and Selected traits.
● Hint. A brief, localized phrase that describes the results of an action on an element. Examples are “Adds
a title” or “Opens the shopping list.”
● Frame. The frame of the element in screen coordinates, which is given by the CGRect structure that
specifies an element’s screen location and size.
● Value. The current value of an element, when the value is not represented by the label. For example, the
label for a slider might be “Speed,” but its current value might be “50%.”
About Controls
Making Controls Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
121
Controls automatically provide value, frame, and default trait information. You can set a label, hint, and adjust
the list of traits using the Identity Inspector in Interface Builder.
For more information, see Accessibility Programming Guide for iOS.
About Controls
Making Controls Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
122
Buttons let a user initiate behavior with a tap. You communicate a button’s function through a textual label
or with an image. Your app changes button appearance based upon user touch interactions, using highlighting,
changes in the label or image, color, and state to indicate the button action dynamically.
Buttons allow the user to:
● Initiate behavior with a tap
● Initiate an action in the app with a single simple gesture
Implementation: Buttons are implemented in the UIButton class and discussed in the UIButton Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
123
Buttons
Configuring Buttons
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Buttons
Configuring Buttons
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
124
Setting Button Content
You can set a button’s content using the Type (buttonType) field in the Attributes Inspector. In iOS 7, the
rounded rect button type has been deprecated in favor of the system button, UIButtonTypeSystem. Button
objects can be specified as one of five standard types—system, detail disclosure, info light, info dark, and add
contact. The detail disclosure, info, and add contact button types are supplied with standard image graphics
to indicate their purpose to the user. These images cannot be customized.
There is also a custom type for great versatility in defining a unique interface.
Specifying Button Behavior
Buttons do not need a delegate to function properly; a view controller can define their behavior and functionality
without implementing any delegate protocols.
A button sends the UIControlEventTouchUpInside event when the user taps it. You can respond to this
event by performing some corresponding action in your app, such as saving information. You register the
target-action methods for a button as shown below.
[self.myButton addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
Alternatively, you can Control-drag the button’s Value Changed event from the Connections Inspector to the
action method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
If the Shows Touch On Highlight (showsTouchWhenHighlighted) box is enabled, when a user presses on
the button, there will be a white glow where the touch event occurred on the button.
Buttons
Configuring Buttons
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
125
If your button has a custom image, the Highlighted Adjusts Image (adjustsImageWhenHighlighted) and
Disabled Adjusts Image (adjustsImageWhenDisabled) options allow you to specify whether highlighted
or disabled states affect the appearance of the image. For example, with those options enabled, the image
might get darker when the button is highlighted, and dimmer when the button is disabled.
If your button content extends past the bounds of the button, you can specify which part of the content to
truncate using the Line Break (lineBreakMode) field.
Customizing Button Appearance
You can customize the appearance of a button by setting the properties depicted below.
To customize the appearance of all buttons in your app, use the appearance proxy (for example, [UIButton
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Setting the Button State
A button has four states to configure for appearance—default, highlighted, selected, and disabled. To configure
the button’s appearance for each state, first select the state from the State Config menu in the Attributes
Inspector and then use the other menus and text boxes in the Attributes Inspector’s appearance property
group.
Buttons
Configuring Buttons
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
126
Setting Button Shadow
Shadow offset defines how far the shadow is drawn from the button text. You can customize the offset for
both dimensions using the Shadow Offset (titleShadowOffset) fields.
You can select the Reverses On Highlight (reversesTitleShadowWhenHighlighted) checkbox if you want
your shadow offset to automatically flip directions when the button is in the UIControlStateHighlighted
state.
Note: These shadow properties only have an effect on buttons with plain—not attributed—text.
Adjusting Button Tint
You can specify a custom button tint using the tintColor property. This property sets the color of the button
image and text.
If you do not explicitly set a tint color, the button will inherit its superview’s tint color. For more information,
see “Adjusting View Tint Color” (page 19).
Buttons
Configuring Buttons
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
127
Formatting Button Title
Button can have one of two types of text: plain or attributed. Plain text supports a single set of formatting
attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports
multiple sets of attributes that apply to individual characters or ranges of characters in the string.
The default title is “Button”, intended to be altered to the app need. The title string set in the default state is
used in all other states unless you enter a replacement title string for a specific state. Available title customization
options differ depending on whether you are using plain or attributed text:
Setting Button Images
Using the Image (currentImage) field, you can specify an image to appear within the content of your button.
If the button has a title, this image appears to the left of it, and centered otherwise. The image does not stretch
or condense, so make sure to select an image that is the proper size to appear in your button. Note that this
image will be automatically rendered as a template image within the button, unless you explicitly set its
rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template
Images” (page 19).
The Background (currentBackgroundImage) field allows you to specify an image to appear behind button
content and fill the entire frame of the button. The image you specify will stretch to fill the button if it is too
small. It will be cropped if it is too large.
Buttons
Configuring Buttons
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
128
The images set in the default state are used in all other states unless you enter a replacement image for a
specific state.
Adjusting Edge Insets
The part of your button that makes up your image and text is your content. You can offset this content by
using edge insets. In the Edge field, select whether you want to offset just your title, just your image, or both
together. Depending on your selection, the changes you make to the Inset fields will adjust the
titleEdgeInsets, imageEdgeInsets, and contentEdgeInsets properties, respectively.
There should be no reason for you to adjust the edge insets for info, contact, or disclosure buttons. This
functionality is intended for custom or rounded rectangle buttons only.
Using Auto Layout with Buttons
You can create Auto Layout constraints between a button and other user interface elements. You can create
any type of constraint for a button.
For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Making Buttons Accessible
Buttons are accessible by default. The default accessibility traits for a button are Button and User Interaction
Enabled.
Buttons
Using Auto Layout with Buttons
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
129
The accessibility label, traits, and hint are spoken back to the user when VoiceOver is enabled on a device. The
button’s title overwrites its accessibility label; even if you set a custom value for the label, VoiceOver speaks
the value of the title. VoiceOver speaks this information when a user taps the button once. For example, when
a user taps the Options button in Camera, VoiceOver speaks the following:
"Options. Button. Shows additional camera options."
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Internationalizing Buttons
To internationalize a button, you much provide localized strings for its title text.
For more information, see Internationalization Programming Topics.
Debugging Buttons
When debugging issues with buttons, watch for these common pitfalls:
● Setting images that are the wrong dimensions. A button does not scale or stretch its content images,
but it does does not scale or stretch any custom images that you add to it. For example, if you specify an
on image that is smaller than the switch, you will see the switch’s on tint color in the space that’s not
covered by the image. On the other hand, if you specify an on image that is too big, it can bleed over into
the space intended for the off image. The size of on/off images should be 77 points wide and 27 points
tall.
● A common button development problem is when a button is tapped and nothing responds, or the app
crashes, when all the code seems well formed and in place. This is commonly caused by an error in linking
the button to its action message, often the result of having changed the action message name or the
layout of buttons during user interface or code development.
Elements Similar to a Button
The following element provides similar functionality to a button:
Bar Button. An icon used to execute an action from a toolbar or for navigation in a navigation bar. For more
information, see “Toolbars” (page 104).
Buttons
Internationalizing Buttons
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
130
A date picker is a control used for selecting a specific date, time, or both. It also provides an interface for a
countdown timer, although it does not implement the functionality. Date pickers provide a straightforward
interface for managing date and time selection, allowing users to specify a particular date quickly and efficiently.
Date pickers allow the user to:
● Specify a particular date and/or time
● Use a countdown timer interface
Implementation: Date pickers are implemented in the UIDatePicker class and discussed in the UIDatePicker
Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
131
Date Pickers
Configuring Date Pickers
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Setting Date Picker Values
A date picker’s currently selected time displays at the center of the picker. This value defaults to the time the
picker object was created, but you can adjust this value using the Date (date) field in Attributes Inspector.
Use the Minimum Date (minimumDate) and Maximum Date (maximumDate) fields to constrain the date picker’s
Date Pickers
Configuring Date Pickers
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
132
range. For example, if you are asking the user to input a birthday, you might set the maximum date to the
current year. Creating a date scope that aligns with your picker’s intended functionality simplifies the user’s
task of finding and setting the correct date.
When a date picker is in the countdown mode, you can use the Timer (countDownDuration) field to specify
the seconds from which the countdown timer should count down. This value is ignored if the date picker is
not in UIDatePickerModeCountDownTimer mode. Note that even though the timer shows a countdown
in seconds, a user can only specify minute intervals to count down from.
Note: A date picker object presents the countdown timer but does not implement it; the application
must set up an NSTimer object and update the seconds as they’re counted down.
Specifying Date Picker Behavior
Date pickers do not need a delegate to function properly; their parent view controller can define their behavior
without implementing any delegate protocols.
A date picker sends the UIControlEventValueChanged event when the user finishes rotating one of the
wheels to change the date or time. You can respond to this event by performing some corresponding action
in your app, such as updating the time for a calendar event. You register the target-action methods for a date
picker as shown below.
Date Pickers
Configuring Date Pickers
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
133
[self.myDatePicker addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
Alternatively, you can Control-drag the date picker’s Value Changed event from the Connections Inspector to
the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
The most important setting in determining a date picker’s functionality is its mode. A date picker’s mode
determines what content it displays to the user, as well as how it behaves. There are four mode settings: date
and time, date only, time only, or countdown timer. The date and/or time modes allow users to select a specific
point in time. The countdown timer allows users to specify a relative time period until an event occurs. You
can specify one of these options using the Mode (datePickerMode) field in Attributes Inspector.
You can choose a specific locale for your date picker to appear in by adjusting the “Locale” (locale) field. For
more information, see “Internationalizing Date Pickers” (page 135).
You can also specify the interval at which the date picker displays minutes. A smaller interval gives users more
precise control over selecting a date picker time. Choose an interval in the Interval (minuteInterval) field.
Customizing Date Picker Appearance
You cannot customize the appearance of date pickers.
Using Auto Layout with Date Pickers
You can create Auto Layout constraints between a date picker and other user interface elements. You can
create any type of constraint for a date picker besides a baseline constraint.
Date Pickers
Using Auto Layout with Date Pickers
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
134
Date pickers usually reside at the bottom of the screen in all device orientations. Select “Bottom Space to
Superview” and set the relation equal to 0 for the date picker to pin to the bottom of the screen in all device
orientations.
For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Making Date Pickers Accessible
Date pickers are accessible by default. Each rotating wheel in the date picker is its own accessibility element
and has the “Adjustable” (UIAccessibilityTraitAdjustable) trait.
The accessibility value, traits, and hint for each picker wheel are spoken back to the user when VoiceOver is
enabled on a device. VoiceOver speaks this information when a user taps on a picker wheel. For example, when
a user taps the hours column on the Add Alarm page (Clock > Alarm > Add), VoiceOver speaks the following:
"2 o'clock. Picker item. Adjustable. Swipe up or down with one finger to adjust
the value."
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Internationalizing Date Pickers
Date pickers handle their own internationalization; the only thing you need to do it specify the appropriate
locale. You can choose a specific locale for your date picker to appear in by setting the “Locale” (locale) field
in Attributes Inspector. This changes the language that the date picker is presented in, but also the format of
the date and time (for example, certain locales present days before month names, or prefer a 24-hour clock
over a 12-hour clock). The width of the date picker automatically accommodates for the length of the localization.
To use the system language, leave this property to default.
For more information, see Internationalization Programming Topics.
Debugging Date Pickers
When debugging issues with date pickers, watch for these common pitfalls:
Date Pickers
Making Date Pickers Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
135
● Specifying conflicting date bounds. Check the bounds of your minimumDate and maximumDate. If the
maximum date is less than the minimum date, both properties are ignored. The minimum and maximum
dates are also ignored in the countdown-timer mode (UIDatePickerModeCountDownTimer).
● Selecting an incorrect interval. Check that the minuteInterval can be evenly divided into 60; otherwise,
the default value is used (1).
Elements Similar to a Date Picker
The following element provides similar functionality to a date picker:
Picker View. A class like the date picker that can be used for selecting things other than date and time. For
more information, see “Picker Views” (page 62).
Date Pickers
Elements Similar to a Date Picker
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
136
A page control displays a horizontal series of dots, each of which represents a page or screen in an app. Although
a page control doesn’t manage the display of content pages, you can write code that lets users navigate
between pages by tapping the control. You can see examples of page controls in Weather—when you set
more than one location—and in the summary, chart, and news view in Stocks (in portrait orientation). Typically,
a page control is used with another view—such as a scroll view—that manages the pages and handles scrolling,
panning, and zooming of the content. In this scenario, the scroll view usually uses paging mode to display the
content, which is divided into separate views or into separate areas of one view.
Page controls allow the user to:
● Have a visual indication of which page is currently displayed
● Navigate between pages in an app
Implementation: Page controls are implemented in the UIPageControl class and discussed in the
UIPageControl Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
137
Page Controls
Configuring Page Controls
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
Specifying Page Control Values
To specify the number of dots the page control should display, you can use the the # of Pages (numberOfPages)
field in the Attributes Inspector. Note that when you create a page control in Interface Builder, the default
number of dots is 3; when you create a page control programmatically, the default number of dots is 0.
Use the Current (currentPage) field to specify the currently selected page. Note that page index begins at
0 instead of 1, so the maximum index of the currently selected page is one less than the total number of pages.
Specifying Page Control Behavior
Page controls need a delegate to handle user interaction. A page control doesn't automatically stay synchronized
with the currently open page—or let users tap the control to transition between pages—unless you enable
these actions in your app. To ensure that a page control's current-page dot corresponds to the page that is
currently open in the scroll view, implement the UIScrollViewDelegate protocol in your view controller.
Then, update the page control in the scrollViewDidScroll: delegate method and set the page control's
currentPage property to the current page.
Page Controls
Configuring Page Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
138
A page control sends the UIControlEventValueChanged event when the user taps it. You can respond to
this event by performing some corresponding action in your app, such as transitioning to a different page in
the scroll view. You register the target-action methods for a page control as shown below.
[self.myPageControl addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
Alternatively, you can Control-drag the page control’s Value Changed event from the Connections Inspector
to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
By default, a page control displays one dot when an app contains only one page. To set the page control to
display no dots when there is only one page, select the Hides for Single Page (hidesForSinglePage) checkbox
in the Attributes Inspector.
You can also choose to delay updating the page control’s display when the current page changes. If the Defers
Page Display (defersCurrentPageDisplay) box is enabled, when the user clicks the control to go to a new
page, the class defers updating the page control until it calls updateCurrentPageDisplay. This behavior is
off by default, which means the page indicator updates immediately.
Customizing Page Control Appearance
You can customize the appearance of a page control by setting the properties depicted below.
To customize the appearance of all page controls in your app, use the appearance proxy (for example,
[UIPageControl appearance]). For more information about appearance proxies, see “Using Appearance
Proxies” (page 18).
Page Controls
Configuring Page Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
139
Adjusting Page Control Tint
The only way to customize the appearance of a page control is by setting custom tints for the dots representing
each page. The Current Page (currentPageIndicatorTintColor) field affects the color of the dot
representing the currently displayed page, and the Tint Color (pageIndicatorTintColor) field affects the
color of the dots representing every other page. The default color is white for the current page dot, and
translucent gray for the other page dots.
If you want your custom colors to be translucent, you must specify a color with an alpha value of less than 1.0.
This must be done programmatically, as in the following example:
self.myPageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:0.0
green:0.0 blue:1.0 alpha:0.5];
self.myPageControl.pageIndicatorTintColor = [UIColor colorWithRed:1.0 green:0.0
blue:0.0 alpha:0.5];
Using Auto Layout with Page Controls
You can create auto layout constraints between a page control and other user interface elements. You can
create any type of constraint for a page control besides a baseline constraint.
To keep a page control centered onscreen, you can use auto layout to pin a page control to its superview or
align it with other elements. Typically, you leave space for a page control at the bottom of the screen, below
the view that displays the pages.
For general information about using auto layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Making Page Controls Accessible
Page controls are accessible by default. The default accessibility traits for a page control are Updates Frequently
and User Interaction Enabled. The Updates Frequently accessibility trait means that the page control doesn't
send update notifications when its state changes. This trait tells an assistive app that it should poll for changes
in the page control when necessary.
Page Controls
Using Auto Layout with Page Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
140
When the user interacts with a page control, VoiceOver speaks "page x of y" where x is the current page and
y is the total number of pages.
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Internationalizing Text Fields
Page controls have no special properties related to internationalization.
For more information, see Internationalization Programming Topics.
Debugging Page Controls
When debugging issues with page controls, watch for this common pitfall:
Selecting an out of range current page. If you try to set a page control’s current page to be higher than the
index of the last page, it will be set equal to the index of the last page. If you try to set a page control’s current
page to be lower than 0, it will be set to 0.
Elements Similar to a Page Control
The following elements provide similar functionality to a page control:
● Scroll View. A class that supports a page-by-page scrolling experience in addition to panning and zooming
of content. For more information, see “Scroll Views” (page 69).
● Page View Controller. A class that displays multiple content views in a book-like format and enables
animated transitions between pages. For more information, see UIPageViewController Class Reference.
Page Controls
Internationalizing Text Fields
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
141
A segmented control is a horizontal control made of multiple segments, each segment functioning as a discrete
button.
Segmented controls allow the user to:
● Interact with a compact group of a number of controls
Implementation: Segmented controls are implemented in the UISegmentedControl class and discussed in
the UISegmentedControl Class Reference.
Configuring Segmented Controls
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. As you will read, a few configurations cannot be made through the
Attributes Inspector, so you must make them programmatically.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
142
Segmented Controls
Setting Segmented Control Values
Segmented controls are made up of a number of individual buttons called segments. You can choose the
number of segments by setting the Segments (numberOfSegments) field. By default, a segmented control is
created with two segments.
Content for each segment is set individually. Using the Segment field, you can select a particular segment to
modify its content. A segment may either have a text title or an image, but not both. Use the Title
(titleForSegmentAtIndex:) or Image (imageForSegmentAtIndex:) fields to set one of these content
properties. As stated in the HI guidelines, avoid creating a segmented control with some segments that contain
text and others that images; just choose one or the other.
Specifying Segmented Control Behavior
Segmented controls do not need a delegate to function properly; their parent view controller can define their
behavior without implementing any delegate protocols.
A segmented control sends the UIControlEventValueChanged event when the user presses one of the
segments. You can respond to this event by performing some corresponding action in your app, such as
switching to a different layout. You register the target-action methods for a segmented control as shown
below.
[self.mySegmentedControl addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
Segmented Controls
Configuring Segmented Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
143
Alternatively, you can Control-drag the segmented control’s Value Changed event from the Connections
Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page
118).
If you set a segmented control to have a momentary selection style, its segments do not stay in a selected
state when pressed. Instead, they are momentarily highlighted and then restored back to the normal control
state. If you would like to enable this behavior, select the Momentary (momentary) checkbox in the Attributes
Inspector. Note that setting the momentary selection behavior affects every segment in a segmented control;
you cannot have a control with some momentary segments and some regular segments.
You can specify whether a given segment is enabled or disabled. A user cannot interact with a segment that
is disabled. Use the Enabled (isEnabledForSegmentAtIndex:) checkbox to specify whether a given segment
is enabled for user interaction. Additionally, you can specify whether a particular segment is currently selected
using the Selected (selectedSegmentIndex) checkbox. Note that only one segment can be selected at a
time; if you set the selection for a given segment, the previously selected segment will become unselected.
Segmented Controls
Configuring Segmented Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
144
Customizing Segmented Control Appearance
You can customize the appearance of a segmented control by setting the properties depicted below.
To customize the appearance of all segmented controls in your app, use the appearance proxy (for example,
[UISegmentedControl appearance]). For more information about appearance proxies, see “Using
Appearance Proxies” (page 18).
Adjusting Segmented Control Tint
You can specify a custom segmented control tint using the Tint (tintColor) field. This property sets the color
of the segment images, text, dividers, borders, and selected segment. A translucent version of this color is also
used to tint a segment when it is pressed and transitioning to being selected, as shown on the first segment
below.
If you do not explicitly set a tint color, the segmented control will inherit its superview’s tint color. For more
information, see “Adjusting View Tint Color” (page 19).
Segmented Controls
Configuring Segmented Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
145
Specifying Segmented Control Style
You cannot customize the segmented control’s style on iOS 7. Segmented controls only have one style, and
the Style (segmentedControlStyle) field has been deprecated.
Specifying Segment Content Offset
If you want the content of a particular segment to be offset from its default position, you can alter it using the
Content Offset fields in Attributes Inspector.
Setting Segmented Control Images
If you need to customize the appearance of your segmented control beyond standard tinting, you might
consider doing so using custom images. Since segmented controls have different metrics for portrait and
landscape device orientations, remember to specify an appropriate image for each set of metrics.
You can set a background image for each control state of your segmented control using the
backgroundImageForState:barMetrics: method. You should also specify divider images for each
combination of left and right segment states to give selected or highlighted segments a different look than
segments in a normal state, as shown here:
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
[mySegmentedControl setDividerImage:image2 forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
[mySegmentedControl setDividerImage:image3 forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateSelected barMetrics:barMetrics];
Formatting Segment Titles
The titleTextAttributesForState: property specifies the attributes for displaying the segment’s title
text. You can specify the font, text color, text shadow color, and text shadow offset for the title in the text
attributes dictionary, using the text attribute keys described in NSString UIKit Additions Reference.
Segmented Controls
Configuring Segmented Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
146
Setting Segment Glyphs
You can use an image instead of title text for your segments. Note that a segment image will be automatically
rendered as a template image within a segmented control, unless you explicitly set its rendering mode to
UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19).
Using Auto Layout with Segmented Controls
You can create auto layout constraints between a segmented control and other user interface elements. You
can create any type of constraint for a segmented control.
For general information about using auto layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Making Segmented Controls Accessible
The following listing demonstrates how you can set the accessibility label of programmatically-generated
segments.
NSString *title = @"∫";
title.accessibilityLabel = @"Integral";
[segmentedControl insertedSegmentedWithTitle:title];
UIImage *image = [UIImage imageNamed:@"GearImage.png"];
image.accessibilityLabel = @"Settings";
[segmentedControl insertedSegmentWithImage:image];
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Internationalizing Segmented Controls
To internationalize a segmented control, you must provide localized strings for all segment titles. Remember
to test all localizations, as segment size may change unexpectedly when using localized strings.
For more information, see Internationalization Programming Topics.
Debugging Segmented Controls
When debugging issues with segmented controls, watch for these common pitfalls:
Segmented Controls
Debugging Segmented Controls
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
147
● Specifying conflicting appearance settings. When customizing segment content with text or images,
use one or the other, but not both. A segment cannot have both text and an image as its content. Whichever
content property was set last will override the other one.
● Not setting custom images for every control state. If you use custom background and divider images
for your segmented control, remember to set an image for every possible UIControlState combination.
Any control state that does not have a corresponding custom image assigned to it will display the standard
image instead. If you set one custom image, make sure to set them all.
Elements Similar to a Segmented Control
The following elements provide similar functionality to a segmented control:
● Tab Bar. A class used for navigating between views in an app. You should use a tab bar instead of a
segmented control when you want to let the user move back and forth between distinct pages in your
app. For more information, see “Tab Bars” (page 83).
● Toolbar. A class that allows users to perform certain actions in the current context. For more information,
see “Toolbars” (page 104).
Segmented Controls
Elements Similar to a Segmented Control
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
148
Sliders enable users to interactively modify some adjustable value in an app, such as speaker volume or screen
brightness. For example, in GarageBand, sliders allow users to mix different settings for various effects. Users
control a slider by moving its current value indicator along a continuous range of values between a specified
minimum and maximum.
Sliders allow the user to:
● Make smooth and continuous adjustments to a value
● Have relative control over a value within a range
● Set a value with a single simple gesture
Implementation: Sliders are implemented in the UISlider class and discussed in the UISlider Class Reference.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
149
Sliders
Configuring Sliders
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
You can customize the appearance of all sliders in your app using the appearance proxy (for example,
[UISlider appearance]), or just of a single control. For more information about appearance proxies, see
“Using Appearance Proxies” (page 18).
Setting Slider Values
You can configure a minimum, maximum, and current value for your slider. By default, a slider’s minimum is
set to 0, its maximum is set to 1, and its current value is set to 0.5. You can change these values by adjusting
the Minimum (minimumValue), Maximum (maximumValue), and Current (value) fields in the Attributes
Inspector.
Sliders
Configuring Sliders
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
150
Specifying Slider Behavior
Sliders do not need a delegate to function properly; their parent view controller can define their behavior
without implementing any delegate protocols.
A slider sends the UIControlEventValueChanged event when the user interacts it. You can respond to this
event by performing some corresponding action in your app, such as adjusting music volume. You register
the target-action methods for a slider as shown below.
[self.mySlider addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
Alternatively, you can Control-drag the slider’s Value Changed event from the Connections Inspector to the
action method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
You can specify when a slider’s UIControlEventValueChanged events are sent by toggling the Continuous
(continuous) checkbox in the Attributes Inspector. In continuous delivery, the slider sends multiple value
changed events as the user moves the thumb. In noncontinuous delivery, the slider sends one value changed
event when the user releases the thumb. Continuous control event delivery is enabled by default.
Customizing Slider Appearance
You can customize the appearance of a slider by setting the properties depicted below.
To customize the appearance of all sliders in your app, use the appearance proxy (for example, [UISlider
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Sliders
Configuring Sliders
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
151
Setting Minimum and Maximum Value Images
The most common way to customize the slider’s appearance is to provide custom minimum and maximum
value images. You can set a slider’s minimum and maximum value images in Interface Builder by selecting
custom images in the Min Image (minimumValueImage) and Max Image (maximumValueImage) fields in the
Attributes Inspector.
These images sit at either end of the slider control and indicate which value that end of the slider represents.
For example, a slider used to control volume might display a speaker with no sound waves emanating from it
for the minimum value and display a speaker with many sound waves emanating from it for the maximum
value, as illustrated here.
Adjusting Slider Tint
You can also set custom tints for each part of a slider. The minimum track image contains a blue highlight by
default, while the maximum track and thumb images contain a white highlight. You can assign different tints
for all of the standard parts provided by the slider. This can be done in the Attributes Inspector by setting the
Min Track Tint (minimumTrackTintColor), Max Track Tint (maximumTrackTintColor), and Thumb Tint
(thumbTintColor) fields.
Note that you can only adjust the tint of the default track and thumb images, not custom images. Setting the
tint of a part of the slider that has custom images associated with it will remove those images.
Setting Track and Thumb Images Programmatically
Slider controls draw the track using two customizable images. The region between the thumb and the end of
the track associated with the slider’s minimum value is drawn using the minimum track image. The region
between the thumb and the end of the track associated with the slider’s maximum value is drawn using the
maximum track image. Different track images are used to provide context as to which end contains the minimum
Sliders
Configuring Sliders
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
152
value. You can customize their appearance by assigning different pairs of track images to each UIControlState
of the slider. Assigning different images to each state lets you customize the appearance of the slider when it
is enabled, disabled, highlighted, and so on.
Use stretchable images for the slider’s track to create custom track images of any arbitrary width. You can
create a stretchable image by using the UIImage method resizableImageWithCapInsets:. Use this
method to add cap insets to an image or to change the existing cap insets of an image. During scaling or
resizing of the image, areas covered by a cap are not scaled or resized. Instead, the pixel area not covered by
the cap in each direction is tiled, left-to-right and top-to-bottom, to resize the image. For best performance,
use a single-pixel image.
You can also customize the appearance of the thumb. Like the track images, you can assign different thumb
images to each control state of the slider. To use a custom thumb image, add the image you wish to use to
your Xcode project, and use it to create a UIImage. Use this UIImage to programmatically set the thumb
image for your slider, as shown here. The same steps apply for the track images.
UIImage *thumbImage = [UIImage imageNamed:@"custom_thumb.png"];
[self.mySlider setThumbImage:thumbImage forState:UIControlStateNormal];
Track and thumb images can only be customized programmatically, as there is no process for accomplishing
this task in the Attributes Inspector.
Using Auto Layout with Sliders
You can create Auto Layout constraints between a slider and other user interface elements. You can create
any type of constraint for a slider besides a baseline constraint.
To keep a slider centered and adjust its width according to device orientation or screen size, you can use Auto
Layout to pin it to its superview. Using the Auto Layout “Pin” menu, create “Leading Space to Superview” and
“Trailing Space to Superview” constraints and set their values equal to each other. Doing this ensures that the
endpoints of your slider are a specified distance from the edges of its superview. With these constraints, the
slider stays centered and its width adjusts automatically for different device orientations and screen sizes.
For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Sliders
Using Auto Layout with Sliders
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
153
Making Sliders Accessible
Sliders are accessible by default. The default accessibility traits for a slider are User Interaction Enabled and
Adjustable.
When enabled on a device, VoiceOver speaks the accessibility label, value, traits, and hint are spoken back to
the user. VoiceOver speaks this information when a user swipes up and down (not left and right) over the
slider. For example, using the Ringer and Alerts volume slider (Settings > Sounds > Ringer and Alerts), VoiceOver
speaks the following:
"Sound volume: 13 percent. Adjustable. Swipe up or down with one finger to adjust
the value."
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Internationalizing Sliders
Sliders have no special properties related to internationalization. However, if you use a slider with a label, make
sure you provide localized strings for the label.
For more information, see Internationalization Programming Topics.
Debugging Sliders
When debugging issues with sliders, watch for these common pitfalls:
● Specifying conflicting appearance settings. When customizing slider appearance with images or tint,
use one option or the other, but not both. Conflicting settings for track and thumb appearance will be
resolved in favor of the most recently set value. For example, setting a new minimum track image for any
state clears any custom tint color you may have provided for minimum track images. Similarly, setting the
thumb tint color removes any custom thumb images associated with the slider.
● Selecting an out of range value. If you try to programmatically set a slider’s current value to be below
the minimum or above the maximum, it is set to the minimum or maximum instead. However, if you try
to do this using Interface Builder, the behavior is much different. For example, let's say your slider has a
minimum value of 0, a maximum value of 5, and the current value is set to 1. If you change the current
value to 999, the maximum value for the slider automatically changes to 999 because that value is higher
than the maximum value, so Interface Builder adjusts accordingly.
Sliders
Making Sliders Accessible
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
154
● Not setting custom images for every control state. If you use custom track and thumb images for your
slider, remember to set an image for every possible UIControlState. Any control state that does not
have a corresponding custom image assigned to it will display the standard image instead. If you set one
custom image, make sure to set them all.
Elements Similar to a Slider
The following elements provide similar functionality to a slider:
● Switch. A control that represents an on/off toggle button. You should use a switch instead of a slider when
you want to give users a choice between two opposing, discrete options instead of a range of values. For
more information, see “Switches” (page 161).
● Stepper. A control that uses a set of two buttons for incrementing or decrementing a value. You should
use a stepper instead of a slider when you want to give users very precise control over the value of an
element. For more information, see “Steppers” (page 156).
Sliders
Elements Similar to a Slider
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
155
A stepper lets the user adjust a value by increasing and decreasing it in small steps. Steppers are used in
situations where a user needs to adjust a value by a small amount.
Steppers allow the user to:
● Make discrete and incremental adjustments to a value
● Have precise control over a value within a range
Implementation: Steppers are implemented in the UIStepper class. For API reference, see UIStepper Class
Reference.
Configuring Steppers
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
156
Steppers
You can customize the appearance of all steppers in your app using the appearance proxy (for example,
[UIStepper appearance]), or just of a single control. For more information about appearance proxies, see
“Using Appearance Proxies” (page 18).
Setting Stepper Values
Configure a minimum, maximum, and current value for the stepper by setting these properties in Interface
Builder. By default, a stepper’s minimum is set to 0, its maximum is set to 100, and its current value is set to 0.
You can change these values by adjusting the Minimum (minimumValue), Maximum (maximumValue), and
Current (value) fields.
Steppers also allow you to specify step size, the amount by which the current value changes when the increase
or decrease buttons are pressed. The default step size is 1. The corresponding Attributes Inspector field is called
Step (stepValue).
Specifying Stepper Behavior
Steppers do not need a delegate to function properly; their parent view controller can define their behavior
without implementing any delegate protocols.
A stepper sends the UIControlEventValueChanged event when the user interacts it. You can respond to
this event by performing some corresponding action in your app, such as adjusting music volume. You register
the target-action methods for a page control as shown below.
[self.myStepper addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
Alternatively, you can Control-drag the stepper’s Value Changed event from the Connections Inspector to the
action method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
You can specify when a stepper’s UIControlEventValueChanged events are sent by toggling the “Continuous”
(continuous) checkbox in the Attributes Inspector. In continuous delivery, the stepper sends multiple Value
Changed events while the user keeps pressing on the stepper. In noncontinuous delivery, the stepper sends
one Value Changed event when the user releases the stepper. Continuous control event delivery is enabled
by default.
Steppers
Configuring Steppers
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
157
A stepper defaults to autorepeat, which means that pressing and holding one of its buttons increments or
decrements the stepper’s value repeatedly. The rate of change depends on how long the user continues
pressing the control. The user can hold the stepper to quickly approach a desired value, and then increment
or decrement to the desired value. Uncheck the “Autorepeat” (autorepeat) box if you want the stepper to
be incremented or decremented one step at a time.
You can set a stepper to wrap around to the minimum value when you try to increment it past its
maximum—and vice versa. This functionality is disabled by default; to enable it, check the “Wrap” (wraps)
box.
Customizing Stepper Appearance
You can customize the appearance of a stepper by setting the properties depicted below.
To customize the appearance of all steppers in your app, use the appearance proxy (for example, [UIStepper
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Adjusting Stepper Tint Programmatically
You can specify a custom stepper tint by setting the tintColor property programmatically. This property
sets the color of the glyphs, divider, and border of the stepper. A translucent version of this color is also used
to tint a stepper button when it is pressed down, as shown on the increment button below.
Steppers
Configuring Steppers
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
158
If you do not explicitly set a tint color, the stepper will inherit its superview’s tint color. For more information,
see “Adjusting View Tint Color” (page 19).
Setting Stepper Glyphs
The increment and decrement images are the glyphs that sit on top of each stepper button. They appear on
top of the background image. Use the setDecrementImage:forState: and
setIncrementImage:forState: methods to specify custom increment and decrement images for each
control state. Note that an increment or decrement image will be automatically rendered as a template image
within a toolbar, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal.
For more information, see “Using Template Images” (page 19).
Setting Stepper Images
You can set custom images for each UIControlState of a stepper. For more information about control states,
see “Understanding Control States” (page 117).
A stepper can have a background image that covers the entirety of the control except for the divider, filling
the entire frame of the stepper. Use the backgroundImageForState: method to set a background image
for each control state of the stepper.
To strengthen the visual effect of a stepper button being pressed, you can set custom divider images for
different combinations of button states: increment button pressed, decrement button pressed, and neither
pressed. Note that it is impossible to press both buttons at the same time. Use the
setDividerImage:forLeftSegmentState:rightSegmentState: method to specify custom divider
images. Don’t forget to set an image for every state.
Using Auto Layout with Steppers
You can create Auto Layout constraints between a stepper and other user interface elements. You can create
any type of constraint for a stepper besides a baseline constraint.
For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Making Steppers Accessible
Steppers are accessible by default. The default accessibility traits for a stepper are User Interaction Enabled
and Adjustable.
Steppers
Using Auto Layout with Steppers
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
159
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Internationalizing Steppers
Steppers have no special properties related to internationalization. However, if you use a stepper with a label,
make sure you provide localized strings for the label.
For more information, see Internationalization Programming Topics.
Elements Similar to a Stepper
The following elements provide similar functionality to a stepper:
● Slider. Use sliders to adjust a value continuously, rather than in discrete steps. Sliders are more appropriate
than steppers for setting a value that has a large range. For more information, see “Sliders” (page 149).
● Picker View. Use pickers to let the user select one of a list of options, rather than stepping through the
range of a value. A picker is more appropriate when selecting from a fixed set of options—for example,
choosing a month. For more information, see “Picker Views” (page 62).
Steppers
Internationalizing Steppers
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
160
A switch lets the user turn an option on and off. You see switches used throughout the Settings app to let a
user quickly toggle a specific setting.
Switches allow the user to:
● Choose between two mutually exclusive options
● Quickly toggle an option on and off
Implementation: Sliders are implemented in the UISwitch class and discussed in the UISwitch.
Configuring Switches
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
161
Switches
Setting Switch Value
Specify a switch’s state to indicate whether the switch is initially on or off. The default value is on. Use the State
(on) field in the Attributes Inspector to accomplish this task.
Specifying Switch Behavior Programmatically
Switches do not need a delegate to function properly; their parent view controller can define their behavior
without implementing any delegate protocols.
A switch sends the UIControlEventValueChanged event when the user toggles it. You can respond to this
event by performing some corresponding action in your app, such as turning a setting on or off. You register
the target-action methods for a switch as shown below.
[mySwitch addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventValueChanged];
Alternatively, you can Control-drag the switch’s Value Changed event from the Connections Inspector to the
action method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
Customizing Switch Appearance
You can customize the appearance of a switch by setting the properties depicted below.
To customize the appearance of all switches in your app, use the appearance proxy (for example, [UISwitch
appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18).
Switches
Configuring Switches
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
162
Adjusting Switch Tint
A switch’s on tint can be configured in the On Tint (onTintColor) field in Attributes Inspector. This is the
color you see when a switch is in the on position. The default on tint is green.
Thumb tint and off tint can only be configured programmatically. By default, the thumb tint is white and can
be set using the thumbTintColor property . You can also set a custom off tint using the tintColor property.
The off tint is light gray by default, but will inherit its superview’s tint color if a custom one is set. For more
information, see “Adjusting View Tint Color” (page 19).
self.mySwitch.thumbTintColor = [UIColor blueColor];
self.mySwitch.tintColor = [UIColor redColor];
Using Auto Layout with Switches
Switches need a label to tell the user what they are for. To label a switch, drag a label out of the elements
library. Make a bottom alignment constraint between their baselines, and a horizontal space constraint between
them of standard size.
For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Making Switches Accessible
Switches are accessible by default. A switch’s default accessibility traits are Button and User Interaction Enabled.
Switches are typically used in a table cell. When a table cell with a switch is tapped, VoiceOver speaks the cell
name, state of the switch, and hint are spoken back to the user. For example, when a user taps the Invert Colors
switch (Settings > General > Accessibility), VoiceOver speaks the following:
Invert Colors. Off. Double tap to toggle setting.
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Switches
Using Auto Layout with Switches
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
163
Internationalizing Switches
Switches have no special properties related to internationalization. However, if you use a switch with a label,
make sure you provide localized strings for the label.
For more information, see Internationalization Programming Topics.
Debugging Switches
When debugging issues with sliders, watch for these common pitfalls:
● Setting on/off images that are the wrong dimensions. A switch does not scale or stretch any custom
images that you add to it. For example, if you specify an on image that is smaller than the switch, you will
see the switch’s on tint color in the space that’s not covered by the image. On the other hand, if you specify
an on image that is too big, it can bleed over into the space intended for the off image. The size of on/off
images should be 77 points wide and 27 points tall.
● Specifying conflicting appearance settings. When customizing switch appearance with images or tint,
you can use one option or the other, but not both. Custom images appear on top of the tint layer. While
you may think you are adjusting the tint of the image itself, you’re simply setting the tint for a layer that
is not visible under the image.
Elements Similar to a Switch
The following element provides similar functionality to a switch:
Slider. A control that allows users to make adjustments to a value within a range of value. You should use a
slider instead of a switch when you want to let users select from a range of values instead of giving them a
choice between two opposing, discrete options. For more information, see “Sliders” (page 149).
Switches
Internationalizing Switches
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
164
Text fields allows the user to input a single line of text into an app. You typically use text fields to gather small
amounts of text from the user and perform some immediate action, such as a search operation, based on that
text.
Text fields allow the user to:
● Enter text as input to an app
Implementation: Text fields are implemented in the UITextField class and discussed in the UITextField Class
Reference.
Configuring Text Fields
Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using
the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set
some configurations programmatically. A few configurations cannot be made through the Attributes Inspector,
so you must make them programmatically.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
165
Text Fields
Setting Text Field Content
Set the content of the text field using the Text (text) field. You can select whether you want plain or attributed
text. The placeholder appears in place whenever a text field has no characters (before a user begins typing, or
if the user deletes everything in the text field).
Both placeholder and text can be attributed strings. For information about using attributed text, see “Specifying
Text Appearance” (page 168).
A user can use the Clear button to delete all text in the text field, and display the placeholder string if one is
set. You can specify when the Clear button is displayed to the user using the Clear Button (clearButtonMode)
field. Additionally, you can indicate whether the text field should automatically clear itself when the user begins
editing it by checking the Clear When Editing Begins (clearsOnBeginEditing) box.
Note: The Clear button only appears when there is text shown in the text field, not the placeholder.
Even if you select the “Is always visible” option, it will not appear when only placeholder text appears.
Specifying Text Field Behavior
Text fields need a delegate to handle any custom behaviors, such as displaying additional overlay views when
a user begins editing it. By assigning the parent view controller as the text field’s delegate and implementing
any or all of the UITextFieldDelegate methods, you can implement such custom behaviors.
A text field sends the UIControlEventEditingDidBegin, UIControlEventEditingChanged,
UIControlEventEditingDidEnd, and UIControlEventEditingDidEndOnExit events when the user
edits it. You can respond to these events by performing some corresponding action in your app, such as
updating information as the user types it. You register the target-action methods for a text field as shown
below.
[self.myTextField addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventEditingDidEnd];
Text Fields
Configuring Text Fields
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
166
Alternatively, you can Control-drag the text field’s Value Changed event from the Connections Inspector to
the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118).
A user types content into a text field using a keyboard, which has a number of customization options:
● Keyboard layout. The Keyboard field allows you to select from a number of different keyboard layouts.
Match the keyboard layout to the purpose of the text field. If the user will be entering a web address,
select the URL keyboard. The default keyboard layout is an alphanumeric keyboard in the device’s default
language. For a list of possible keyboard types, see UIKeyboardType. You cannot customize the appearance
of the keyboard on iOS 7.
● Return key. The return key, which appears in the bottom right of the keyboard, allows the user to notify
the system when they are finished editing the text field. You can select one of several standard return key
types by using the Return Key field. The return key is disabled by default, and only becomes enabled when
a user types something into the text field. If you want your user to be able to press the return key any time
the keyboard is open, even if the input is empty or incomplete, you can enable the Auto-enable Return
Key option. Different return keys are intended to provide the user with an understanding of what action
hitting the key will trigger. Note that simply selecting a different return key appearance does not provide
you with the functionality intended by that key; you must implement custom return key behavior yourself
using the textFieldShouldReturn: method in your text field’s delegate.
● Capitalization scheme. The Capitalization field specifies how text should be capitalized in the text field:
no capitalization, every word, every sentence, or every character. Although no capitalization is selected
by default, you should select the capitalization scheme that reflects the intended use of your text field.
For example, if you ask for a user’s full name, you can configure the keyboard to capitalize every word so
the user does not have to do it manually.
● Auto-correction. The Correction field simply disables or enables auto-correct in the text field.
● Secure content. The Secure option is off by default. Enabling it causes the text field to obscure text once
it is typed, allowing the user to safely enter secure content—such as a password—into the field.
You can use the text field delegate methods to handle custom keyboard dismissal.
Text Fields
Configuring Text Fields
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
167
Customizing Text Field Appearance
You can customize the appearance of a text field by setting the properties depicted below.
To customize the appearance of all text fields in your app, use the appearance proxy (for example,
[UITextField appearance]), or just of a single control. For more information about appearance proxies,
see “Using Appearance Proxies” (page 18).
Selecting Border Style
You can select one of the following border styles for your text field by selecting it next to the Border Style
(borderStyle) field:
Specifying Text Appearance
Text views can have one of two types of text: plain or attributed. Plain text supports a single set of formatting
attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports
multiple sets of attributes that apply to individual characters or ranges of characters in the string.
Text Fields
Configuring Text Fields
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
168
Specifying Font Size
By default, the Adjusts to Fit (adjustsFontSizeToFitWidth) box is selected in the Attributes Inspector.
When this option is enabled, the font size of your text label will automatically scale to fit inside the text field.
If you anticipate your text label to change—such as if the string is localized—you should keep this selected.
Setting a minimum font size ensures that your text will never appear smaller than intended. Use the Min Font
Size (minimumFontSize) field if you want to change the value from its default.
Using Images in Text Fields
A text field can have a background image that sits under the content of the text field. Use the Background
(background) field to set a background image for the normal state and the Disabled (disabledBackground)
field to set a background image for when the control is disabled.
Using Auto Layout with Text Fields
You can create Auto Layout constraints between a text field and other user interface elements. You can create
any type of constraint for a text field.
You will generally need to specify what a text field is intended for. You can use a label to do this. Place the
label to the left of the text field and give the label and text field a “Horizontal Spacing” constraint.
For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page
120).
Making Text Fields Accessible
Text fields are accessible by default. The default accessibility traits for a text field are User Interaction Enabled
and Adjustable.
For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121).
Text Fields
Using Auto Layout with Text Fields
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
169
Internationalizing Text Fields
The default language of the device affects the keyboard that pops up with the text field (including the return
key). You don’t need to do anything to enable this functionality; it is enabled by default. However, your text
field should be able to handle input that comes from any language.
For more information, see Internationalization Programming Topics.
Elements Similar to a Text Field
The following elements provide similar functionality to a text field:
● Text View. A text view accepts and displays multiple lines of text. Text views support scrolling and text
editing. You typically use a text view to display a large amount of text, such as the body of an email
message. For more information, see “Text Views” (page 98).
● Label. A label displays static text. Labels are often used in conjunction with controls to describe their
intended purpose, such as explaining which value a button or slider affects. For more information, see
“Labels” (page 49).
Text Fields
Internationalizing Text Fields
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
170
Important: This is a preliminary document for an API or technology in development. Although this document
has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only
by registered members of the applicable Apple Developer program. Apple is supplying this confidential
information to help you plan for the adoption of the technologies and programming interfaces described
herein. This information is subject to change, and software implemented according to this document should
be tested with final operating system software and final documentation. Newer versions of this document
may be provided with future seeds of the API or technology.
● “Activity Indicator View” (page 173)
● “Bar Button Item” (page 175)
● “Bar Item” (page 178)
● “Button” (page 179)
● “Collection Reusable View” (page 185)
● “Collection View” (page 186)
● “Collection View Cell” (page 188)
● “Control” (page 189)
● “Date Picker” (page 191)
● “Image View” (page 194)
● “Label” (page 195)
● “Navigation Bar” (page 200)
● “Navigation Item” (page 201)
● “Page Control” (page 202)
● “Picker View” (page 204)
● “Progress View” (page 205)
● “Scroll View” (page 206)
● “Scroll View” (page 206)
● “Search Bar” (page 211)
● “Segmented Control” (page 215)
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
171
Attributes Inspector Reference
● “Slider” (page 218)
● “Stepper” (page 220)
● “Switch” (page 222)
● “Tab Bar” (page 223)
● “Tab Bar Item” (page 224)
● “Table View” (page 225)
● “Table View Cell” (page 227)
● “Text View” (page 231)
● “Toolbar” (page 238)
● “View” (page 239)
● “Web View” (page 243)
Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
172
Important: This is a preliminary document for an API or technology in development. Although this document
has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only
by registered members of the applicable Apple Developer program. Apple is supplying this confidential
information to help you plan for the adoption of the technologies and programming interfaces described
herein. This information is subject to change, and software implemented according to this document should
be tested with final operating system software and final documentation. Newer versions of this document
may be provided with future seeds of the API or technology.
Activity Indicator View Attributes Inspector Reference
Appearance and Behavior
Style
The basic appearance of the activity indicator.
ArgumentMethodSelection
UIActivityIndicator-
ViewStyleWhiteLarge
activityIndicatorViewStyleLarge White
UIActivityIndicatorViewStyleWhiteactivityIndicatorViewStyleWhite
UIActivityIndicatorViewStyleGrayactivityIndicatorViewStyleGray
Color
The color of the activity indicator.
Access: color
Behavior
Animating
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
173
Activity Indicator View
Whether the activity indicator is moving.
Access: isAnimating
MethodSelection
stopAnimatingUnselected
startAnimatingSelected
Hides When Stopped
Whether the activity indicator is not shown when it is not animating.
ArgumentMethodSelection
NOhidesWhenStoppedUnselected
YEShidesWhenStoppedSelected
Activity Indicator View
Activity Indicator View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
174
Bar Button Item Attributes Inspector Reference
Appearance
Style
The bar button item style.
ArgumentMethodSelection
UIBarButtonItemStylePlainstylePlain
UIBarButtonItemStyleBorderedstyleBordered
UIBarButtonItemStyleDonestyleDone
Identifier
The button type of the bar button item.
To specify a custom button, use initWithTitle:image:tag: or image.
ArgumentMethodSelection
Custom
UIBarButtonSystem-
ItemFlexibleSpace
initWithBarButtonSystemItem:
target:action:
Flexible
Space
UIBarButtonSystem-
ItemFixedSpace
initWithBarButtonSystemItem:
target:action:
Fixed Space
UIBarButtonSystemItemAddinitWithBarButtonSystemItem:
target:action:
Add
UIBarButtonSystemItemEditinitWithBarButtonSystemItem:
target:action:
Edit
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
175
Bar Button Item
ArgumentMethodSelection
UIBarButtonSystemItemDoneinitWithBarButtonSystemItem:
target:action:
Done
UIBarButtonSystemItemCancelinitWithBarButtonSystemItem:
target:action:
Cancel
UIBarButtonSystemItemSaveinitWithBarButtonSystemItem:
target:action:
Save
UIBarButtonSystemItemUndoinitWithBarButtonSystemItem:
target:action:
Undo
UIBarButtonSystemItemRedoinitWithBarButtonSystemItem:
target:action:
Redo
UIBarButtonSystem-
ItemCompose
initWithBarButtonSystemItem:
target:action:
Compose
UIBarButtonSystemItemReplyinitWithBarButtonSystemItem:
target:action:
Reply
UIBarButtonSystemItemActioninitWithBarButtonSystemItem:
target:action:
Action
UIBarButtonSystem-
ItemOrganize
initWithBarButtonSystemItem:
target:action:
Organize
UIBarButtonSystemItemTrashinitWithBarButtonSystemItem:
target:action:
Trash
UIBarButtonSystem-
ItemBookmarks
initWithBarButtonSystemItem:
target:action:
Bookmarks
UIBarButtonSystemItemSearchinitWithBarButtonSystemItem:
target:action:
Search
UIBarButtonSystem-
ItemFlexibleSpace
initWithBarButtonSystemItem:
target:action:
Refresh
UIBarButtonSystemItemStopinitWithBarButtonSystemItem:
target:action:
Stop
UIBarButtonSystemItemCamerainitWithBarButtonSystemItem:
target:action:
Camera
Bar Button Item
Bar Button Item Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
176
ArgumentMethodSelection
UIBarButtonSystemItemPlayinitWithBarButtonSystemItem:
target:action:
Play
UIBarButtonSystemItemPauseinitWithBarButtonSystemItem:
target:action:
Pause
UIBarButtonSystemItemRewindinitWithBarButtonSystemItem:
target:action:
Rewind
UIBarButtonSystem-
ItemFastForward
initWithBarButtonSystemItem:
target:action:
Fast Forward
UIBarButtonSystem-
ItemPageCurl
initWithBarButtonSystemItem:
target:action:
Page Curl
Tint
The bar button item color.
Access: tintColor
Bar Button Item
Bar Button Item Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
177
Bar Item Attributes Inspector Reference
Appearance, Behavior, and Tagging
Title
The bar item title.
Access: title.
Image
The bar item image.
Access: image.
Tag
The bar item tag.
Access: tag.
Enabled
Whether the bar item is enabled.
ArgumentMethodSelection
NOenabledUnselected
YESenabledSelected
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
178
Bar Item
Button Attributes Inspector Reference
Type
Type
The button type, which determines its functionality.
ArgumentMethodSelection
UIButtonTypeCustombuttonTypeCustom
UIButtonTypeRoundedRectbuttonTypeRounded Rect
UIButtonTypeDetailDisclosurebuttonTypeDetail Disclosure
UIButtonTypeInfoLightbuttonTypeInfo Light
UIButtonTypeInfoDarkbuttonTypeInfo Dark
UIButtonTypeContactAddbuttonTypeAdd Contact
Appearance
This group specifies the appearance of the button in each of its possible states.
State Config
The button state to configure.
Choose a state, and then configure the remaining properties in this group. The settings are applied to those
properties when the button goes to that state.
ArgumentMethodSelection
UIControlStateNormalstateDefault
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
179
Button
ArgumentMethodSelection
UIControlStateHighlightedstateHighlighted
UIControlStateSelectedstateSelected
UIControlStateDisabledstateDisabled
Title
Title Type
The type of text to use for the button title when the button is in the state identified by State Config.
Selection
Plain
Attributed
Title Type: Plain
These are the properties you can configure for plain text titles in the state identified by State Config.
Text
The plain text for the button title in the state identified by State Config.
Access: titleForState:, setTitle:forState:.
Font
The font for the button plain text title in the state identified by State Config.
Use <button>.titleLabel.font to access the value of this property.
Text Color
The color for the button plain text title in the state identified by State Config.
Access: titleColorForState:, setTitleColor:forState:.
Shadow Color
The color for the button plain text title in the state identified by State Config.
Button
Button Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
180
Access: titleShadowColorForState:, setTitleShadowColor:forState:.
Title Type: Attributed
These are the properties you can configure for attributed text titles in the state identified by State Config.
Attributed Title Layout
The alignment and other layout characteristics for the button attributed text title in the state identified by
State Config.
You can set these layout characteristics: alignment (left, center, right, justified, and natural), text color,
background color, text direction, line breaking, line height and spacing, paragraph spacing, indentation,
hyphenation, truncation, and header level).
Selection
Left
Center
Right
Justified
Natural
Text Color
Background Color
More
Font
The font for the button attributed text title in the state identified by State Config.
Access: button.titleLabel.font.
Attributed Text
The attributed text for the button title in the state identified by State Config.
Access: attributedTitleForState:.
Image
Button
Button Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
181
The image for the button when it is in the state identified by State Config.
Access: imageForState:, setImage:forState:.
Background
The background image for the button when it is in the state identified by State Config.
Access: backgroundImageForState:, setBackgroundImage:forState:.
Behavior
Shadow Offset
Offset Size
The width and height of the shadow of the button title.
Access: titleShadowOffset.
Reverses On Highlight
Whether the shadow of the button title changes when the button state changes to or from highlighted.
ArgumentMethodSelection
NOreversesTitleShadowWhenHighlightedUnselected
YESreversesTitleShadowWhenHighlightedSelected
Highlight Tint
The color for the button tint.
tintColor
Drawing
Shows Touch On Highlight
Whether the button glows when it is tapped.
ArgumentMethodSelection
NOshowsTouchWhenHighlightedUnselected
Button
Button Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
182
ArgumentMethodSelection
YESshowsTouchWhenHighlightedSelected
Highlighted Adjusts Image
Whether the button image changes when the button state changes to or from highlighted.
ArgumentMethodSelection
NOadjustsImageWhenHighlightedUnselected
YESadjustsImageWhenHighlightedSelected
Disabled Adjusts Image
Whether the button image changes when the button state changes to or from disabled.
ArgumentMethodSelection
NOadjustsImageWhenDisabledUnselected
YESadjustsImageWhenDisabledSelected
Line Break
The line break mode for the button title.
ArgumentMethodSelection
UILineBreakModeCliplineBreakModeClip
UILineBreakModeCharacterWraplineBreakModeCharacter Wrap
UILineBreakModeWordWraplineBreakModeWord Wrap
UILineBreakModeHeadTruncationlineBreakModeTruncate Head
UILineBreakModeMiddleTruncationlineBreakModeTruncate Middle
UILineBreakModeTailTruncationlineBreakModeTruncate Tail
Button
Button Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
183
Edge Insets
Edge insets resize and reposition the effective drawing rectangle for the button’s entire content, its title, and
its image.
Edge
The button edge to configure.
Selection
Content
Title
Image
Inset
The inset or outset margins of the rectangle identified by the Edge property.
You can specify a value for each the edges (top, left, bottom, right). A positive value shrinks (or insets) the
corresponding edge, moving it closer to the center of the button. A negative value expands (or outsets) the
corresponding edge.
Access: contentEdgeInsets, titleEdgeInsets, imageEdgeInsets.
Button
Button Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
184
Collection Reusable View Attributes Inspector Reference
Cell Reuse
Identifier
The collection reusable view reuse identifier.
Access: reuseIdentifier.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
185
Collection Reusable View
Collection View Attributes Inspector Reference
Layout, Scrolling, Header, and Footer
Layout
The layout to use to lay out the collection view content.
Access: collectionViewLayout
Selection
Flow
Custom
Layout: Flow
Scroll Direction
The direction along which the collection view scrolls.
Access: collection_view.collectionViewLayout.scrollDirection
ArgumentMethodSelection
UICollectionViewScrollDirectionVerticalscrollDirectionVertical
UICollectionViewScrollDirectionHorizontalscrollDirectionHorizontal
Accessories
Section Header
Whether the collection view has a header.
Access: collection_view.collectionViewLayout.headerReferenceSize headerReferenceSize.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
186
Collection View
CodeSelection
collection_view.collectionViewLayout.headerReferenceSize
= 0.0
Unselected
collection_view.collectionViewLayout.headerReferenceSize
= // Floating-point value greater than 0.0
Selected
Section Footer
Whether the collection view has a footer.
Access: collection_view.collectionViewLayout.footerReferenceSize footerReferenceSize.
CodeSelection
collection_view.collectionViewLayout.footerReferenceSize
= 0.0
Unselected
collection_view.collectionViewLayout.footerReferenceSize
= // Floating-point value greater than 0.0
Selected
Layout: Custom
Class
The class of the layout to use to lay out the collection view content.
Collection View
Collection View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
187
Collection View Cell Attributes Inspector Reference
Cell Reuse
Identifier
The collection view cell reuse identifier.
Access: reuseIdentifier.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
188
Collection View Cell
Control Attributes Inspector Reference
Layout
Alignment
Horizontal
The horizontal alignment of the content.
ArgumentMethodSelection
UIControlContentHorizontalAlignment-
Left
contentHorizontalAlignmentLeft
UIControlContentHorizontalAlignment-
Center
contentHorizontalAlignmentCenter
UIControlContentHorizontalAlignment-
Right
contentHorizontalAlignmentRight
UIControlContentHorizontalAlignment-
Fill
contentHorizontalAlignmentFill
Vertical
The vertical alignment of the content.
ArgumentMethodSelection
UIControlContentVerticalAlignmentTopcontentVerticalAlignmentTop
UIControlContentVerticalAlignmentCentercontentVerticalAlignmentCenter
UIControlContentVerticalAlignmentBottomcontentVerticalAlignmentBottom
UIControlContentVerticalAlignmentFillcontentVerticalAlignmentFill
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
189
Control
Behavior
Content
Selected
Whether the control is selected.
ArgumentMethodSelection
NOselectedUnselected
YESselectedSelected
Enabled
Whether the user can interact with the control.
ArgumentMethodSelection
NOenabledUnselected
YESenabledSelected
Highlighted
Whether the control is highlighted.
ArgumentMethodChoice
NOhighlightedUnselected
YEShighlightedSelected
Control
Control Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
190
Date Picker Attributes Inspector Reference
Functionality
Mode
The functionality of the date picker.
The mode indicates whether the date picker is a date or time picker, or a count down timer.
ArgumentMethodSelection
UIDatePickerModeTimedatePickerModeTime
UIDatePickerModeDatedatePickerModeDate
UIDatePickerModeDateAndTimedatePickerModeDate and Time
UIDatePickerModeCountDownTimerdatePickerModeCount Down Timer
Locale
The locale for the date picker.
Access: locale.
Interval
The interval at which the date picker displays minutes.
Access: minuteInterval.
Selection
1 minute
2 minutes
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
191
Date Picker
Selection
3 minutes
4 minutes
5 minutes
6 minutes
10 minutes
12 minutes
15 minutes
20 minutes
30 minutes
Date
These properties are unused when the date picker mode is count down timer.
Date
The date the date picker displays.
Access: date.
Constraints
Minimum Date
The earliest date the date picker displays.
Access: minimumDate.
Maximum Date
The latest date the date picker displays.
Access: maximumDate.
Date Picker
Date Picker Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
192
Count Down Timer
Count Down in Seconds
The number of seconds from which the date picker counts down.
Access: countDownDuration.
Date Picker
Date Picker Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
193
Image View Attributes Inspector Reference
Images
The properties in this group are not used when you specify an image sequence using animationImages.
Image
The image displayed in the image view when its state is not highlighted.
Access: image.
Highlighted
The image displayed in the image view when its state is highlighted.
Access: highlightedImage.
Behavior
State
Highlighted
Whether the image view is highlighted.
Toggle this property after setting Image and Highlighted to preview the images for each state.
ArgumentMethodSelection
NOhighlightedUnselected
YEShighlightedSelected
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
194
Image View
Label Attributes Inspector Reference
Text and Behavior
Text
Text Type
The type of the label text.
Selection
Plain
Attributed
Text Type: Plain
This group configures the label plain text.
Text
The label plain text.
Access: text.
Color
The color of the label plain text.
Access: textColor.
Font
The font of the label plain text.
Access: font.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
195
Label
Alignment
The alignment of the label plain text.
ArgumentMethodSelection
NSTextAlignmentLefttextAlignmentLeft
NSTextAlignmentCentertextAlignmentCenter
NSTextAlignmentRighttextAlignmentRight
Text Type: Attributed
This group configures the text selected in Attributed Text.
Attributed Text Layout
The alignment and other layout characteristics of the selected attributed text.
To set alignment and other layout characteristics of part of the attributed text in code, you need to create an
attributed string with the desired characteristics and assign it to attributedText.
Selection
Left
Center
Right
Justified
Natural
Text Color
Background Color
More
Font
The font of the selected attributed text.
Access: font.
Label
Label Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
196
Attributed Text
The label attributed text.
Access: attributedText.
Lines
The maximum number of lines for the label text.
Set to 0 for an unlimited number of lines.
Access: numberOfLines.
Behavior
Enabled
Whether the label is enabled.
ArgumentMethodSelection
NOenabledUnselected
YESenabledSelected
Highlighted
Whether the label is highlighted.
Toggle this property after setting the text highlight color to preview the highlighted label.
ArgumentMethodSelection
NOhighlightedUnselected
YEShighlightedSelected
Text Baseline and Line Breaks
Baseline
How to adjust the text baseline so that the text fits in the label.
Label
Label Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
197
ArgumentMethodSelection
UIBaselineAdjustmentAlignBaselinesbaselineAdjustmentAlign Baselines
UIBaselineAdjustmentAlignCentersbaselineAdjustmentAlign Centers
UIBaselineAdjustmentNonebaselineAdjustmentNone
Line Breaks
The line break mode of the label text.
ArgumentMethodSelection
UILineBreakModeCliplineBreakModeClip
UILineBreakModeCharacterWraplineBreakModeCharacter Wrap
UILineBreakModeWordWraplineBreakModeWord Wrap
UILineBreakModeHeadTruncationlineBreakModeTruncate Head
UILineBreakModeMiddleTruncationlineBreakModeTruncate Middle
UILineBreakModeTailTruncationlineBreakModeTruncate Tail
Text Sizing
Autoshrink
How to shrink the label text so that it fits in the label.
MethodArgumentMethodSelection
NOadjustsFontSize-
ToFitWidth
Fixed Font Size
minimumScaleFactorYESadjustsFontSize-
ToFitWidth
Minimum Font Scale
minimumFontSizeYESadjustsFontSize-
ToFitWidth
Minimum Font Size
Tighten Letter Spacing
Label
Label Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
198
Whether to reduce the label text letter spacing so that it fits in the label.
ArgumentMethodSelection
NOadjustsLetterSpacingToFitWidthUnselected
YESadjustsLetterSpacingToFitWidthSelected
Text Highlight and Shadow
Highlighted
The color for the label text when the label is highlighted.
This property applies only to plain text labels.
Access: highlightedTextColor.
Shadow
The color of the label text shadow.
Access: shadowColor.
Shadow Offset
The offset of the label text shadow.
Access: shadowOffset.
Label
Label Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
199
Navigation Bar Attributes Inspector Reference
Appearance
Style
The basic appearance of the navigation bar.
ArgumentMethodSelection
UIBarStyleDefaultbarStyleDefault
UIBarStyleBlackbarStyleBlack Opaque
UIBarStyleBlackTranslucentbarStyleBlack Translucent
Tint
The color of the navigation bar.
Access: tintColor.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
200
Navigation Bar
Navigation Item Attributes Inspector Reference
PropertyGroup
Title
The navigation item title. Access: title.
Prompt
The navigation item prompt. Access: prompt.
Back Button
The bar button item the navigation item displays when it needs a back button. Access: backBarButtonItem.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
201
Navigation Item
Page Control Attributes Inspector Reference
Behavior and Pages
Number of Pages
The number of pages the page control shows.
Access: numberOfPages
Current
The index of the page control current page.
Access: currentPage
Behavior
Hides for Single Page
Whether the page control is hidden when the number of pages is 1.
ArgumentMethodChoice
NOhidesForSinglePageUnselected
YEShidesForSinglePageSelected
Defers Page Display
Whether the page control defers updating its display when the user selects a page.
When display-update is deferred, the page control does not update its display when the user selects a page.
To update the display, call updateCurrentPageDisplay.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
202
Page Control
ArgumentMethodChoice
NOdefersCurrentPageDisplayUnselected
YESdefersCurrentPageDisplaySelected
Appearance
Tint Color
The color of the page control dots that correspond to non-open pages.
Access: pageIndicatorTintColor
Current Page
The color of the page control dot that corresponds to the currently open page.
Access: currentPageIndicatorTintColor
Page Control
Page Control Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
203
Picker View Attributes Inspector Reference
Behavior
Shows Selection Indicator
Whether the picker view shows the bar that identifies the selected row in each component.
ArgumentMethodSelection
NOshowsSelectionIndicatorUnselected
YESshowsSelectionIndicatorSelected
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
204
Picker View
Progress View Attributes Inspector Reference
Appearance and Progress
Style
The basic appearance of the progress view.
ArgumentMethodSelection
UIProgressViewStyleDefaultprogressViewStyleDefault
UIProgressViewStyleBarprogressViewStyleBar
Progress
The progress view progress.
Access: progress.
Progress Tint
The color of the progress view completed-progress bar.
Access: progressTintColor.
Track Tint
The color of the progress view track.
Access: trackTintColor.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
205
Progress View
Scroll View Attributes Inspector Reference
Appearance
Style
The appearance of the scroll view scroll indicators.
ArgumentMethodSelection
UIScrollViewIndicatorStyleDefaultindicatorStyleDefault
UIScrollViewIndicatorStyleBlackindicatorStyleBlack
UIScrollViewIndicatorStyleWhiteindicatorStyleWhite
Scroll Indicators and Scrolling
Scrollers
Shows Horizontal Scrollers
Whether the scroll view horizontal scroll indicator is visible.
ArgumentMethodSelection
NOshowsHorizontalScrollIndicatorUnselected
YESshowsHorizontalScrollIndicatorSelected
Shows Vertical Scrollers
Whether the scroll view vertical scroll indicator is visible.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
206
Scroll View
ArgumentMethodSelection
NOshowsVerticalScrollIndicatorUnselected
YESshowsVerticalScrollIndicatorSelected
Scrolling Enabled
Whether the user can scroll the scroll view contents.
When scrolling is enabled the user can scroll the scroll view contents.
ArgumentMethodSelection
NOscrollEnabledUnselected
YESscrollEnabledSelected
Paging Enabled
Whether the scroll view stops at regular intervals as the user scrolls.
When paging is enabled the scroll view stops on multiples of the scroll view bounds as the user scrolls.
ArgumentMethodSelection
NOpagingEnabledUnselected
YESpagingEnabledSelected
Direction Lock Enabled
Whether the user can scroll in only one cardinal direction at a time.
When direction lock is enabled the user can scroll in only one cardinal direction at a time, vertically or
horizontally, except when the user scrolls diagonally.
ArgumentMethodSelection
NOdirectionalLockEnabledUnselected
YESdirectionalLockEnabledSelected
Scroll View
Scroll View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
207
Scroll Bounce
Bounce
Bounces
Whether the scroll view bounces when the user scrolls past a content edge.
ArgumentMethodSelection
NObouncesUnselected
YESbouncesSelected
Bounce Horizontally
Whether the scroll view bounces when the user scrolls past a horizontal content edge.
When horizontal bouncing is allowed, the scroll view lets the user scroll horizontally even when the scroll view
content does not fill the scroll view bounds horizontally.
ArgumentMethodSelection
NOalwaysBounceHorizontalUnselected
YESalwaysBounceHorizontalSelected
Bounce Vertically
Whether the scroll view bounces when the user scrolls past a vertical content edge.
When vertical bouncing is allowed, the scroll view lets the user scroll vertically even when the scroll view
content does not fill the scroll view bounds vertically.
ArgumentMethodSelection
NOalwaysBounceVerticalUnselected
YESalwaysBounceVerticalSelected
Scroll View
Scroll View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
208
Zooming
Zoom
Min
The minimum zoom scale factor the user can apply to the scroll view content.
Access: minimumZoomScale.
Max
The maximum zoom scale factor the user can apply to the scroll view content.
Access: maximumZoomScale.
Events and Zoom Bounce
Touch
Bounces Zoom
Whether the scroll view bounces when the user zooms past the scroll view minimum or maximum zoom scale
factors.
ArgumentMethodSelection
NObouncesZoomUnselected
YESbouncesZoomSelected
Delays Content Touches
Whether the scroll view delays the handling of every touch event to determine whether the event is a scrolling
event.
ArgumentMethodSelection
NOdelaysContentTouchesUnselected
YESdelaysContentTouchesSelected
Cancellable Content Touches
Whether the scroll view can convert a touch event into a scroll event to reflect user intent.
Scroll View
Scroll View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
209
When content touches are cancellable, the view can cancel the handling of a touch event and initiate a scroll
event when the user drags.
ArgumentMethodSelection
NOcanCancelContentTouchesUnselected
YEScanCancelContentTouchesSelected
Scroll View
Scroll View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
210
Search Bar Attributes Inspector Reference
Search Term and Captions
Text
The initial search string.
Access: text.
Placeholder
The text that appears when there is no search string.
Access: placeholder.
Prompt
The text that appears above the text field.
Access: prompt.
Appearance
Style
The basic appearance of the search bar.
ArgumentMethodSelection
UIBarStyleDefaultbarStyleDefault
UIBarStyleBlackbarStyleBlack Opaque
UIBarStyleBlackTranslucentbarStyleBlack Translucent
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
211
Search Bar
Tint
The color of the search bar.
Access: tintColor.
Capabilities
Shows Search Results Button
Whether the search bar displays the Search Results button.
ArgumentMethodSelection
NOshowsSearchResultsButtonUnselected
YESshowsSearchResultsButtonSelected
Shows Bookmarks Button
Whether the search bar displays the Bookmarks button.
ArgumentMethodSelection
NOshowsBookmarkButtonUnselected
YESshowsBookmarkButtonSelected
Shows Cancel Button
Whether the search bar displays the Cancel button.
ArgumentMethodSelection
NOshowsCancelButtonUnselected
YESshowsCancelButtonSelected
Shows Scope Bar
Whether the search bar displays the scope bar.
Search Bar
Search Bar Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
212
ArgumentMethodSelection
NOshowsScopeBarUnselected
YESshowsScopeBarSelected
Scope Titles
Scope Title List
The titles of the scope buttons in the scope bar.
Access: scopeButtonTitles.
Text Input
Capitalize
Whether and when the keyboard activates the Shift key while the user types text.
ArgumentMethodSelection
UITextAutocapitalizationTypeNoneautocapitalizationTypeNone
UITextAutocapitalizationTypeWordsautocapitalizationTypeWords
UITextAutocapitalizationTypeSentencesautocapitalizationTypeSentences
UITextAutocapitalization-
TypeAllCharacters
autocapitalizationTypeAll Characters
Correction
Whether to auto-correct text the user types.
ArgumentMethodSelection
UITextAutocorrectionTypeDefaultautocorrectionTypeDefault
UITextAutocorrectionTypeNoautocorrectionTypeNo
UITextAutocorrectionTypeYesautocorrectionTypeYes
Search Bar
Search Bar Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
213
Keyboard
The type of keyboard that appears on text input.
ArgumentMethodSelection
UIKeyboardTypeDefaultkeyboardTypeDefault
UIKeyboardTypeASCIICapablekeyboardTypeASCII Capable
UIKeyboardTypeNumbersAndPunctuationkeyboardTypeNumbers and Punctuation
UIKeyboardTypeURLkeyboardTypeURL
UIKeyboardTypeNumberPadkeyboardTypeNumber Pad
UIKeyboardTypePhonePadkeyboardTypePhone Pad
UIKeyboardTypeEmailAddresskeyboardTypeE-mail Address
Search Bar
Search Bar Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
214
Segmented Control Attributes Inspector Reference
Appearance and Behavior
This group specifies the appearance and behavior for the segmented control.
Style
The basic appearance of the segmented control.
ArgumentMethodSelection
UISegmentedControlStylePlainsegmentedControlStylePlain
UISegmentedControlStyleBorderedsegmentedControlStyleBordered
UISegmentedControlStyleBarsegmentedControlStyleBar
State
Momentary
Whether the segmented control segments are only momentarily selected.
A segmented control selection behavior can be normal or momentary.
● Normal selection. When the user taps a segment, the segment becomes selected (the segmented control
selectedSegmentIndex is set to that segment’s index).
● Momentary selection. When the user taps a segment, the segment does not become selected, but the
segment appears selected while the user holds it.
ArgumentMethodSelection
NOmomentaryUnselected
YESmomentarySelected
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
215
Segmented Control
Tint
The color of the segmented control.
tintColor
Segments
The number of segments in the segmented control.
Access: numberOfSegments.
Segment Appearance and Behavior
This group specifies the appearance and behavior for each of the segmented control segments.
Segment
The segment to configure.
Choose a segment, and then configure the properties in this group.
Title
The title of the segment identified by Segment.
Access: setTitle:forSegmentAtIndex:.
Image
The image of the segment identified by Segment.
Access: setImage:forSegmentAtIndex:.
Behavior
Enabled
Whether segment identified by Segment is enabled.
ArgumentMethodSelection
NOsetEnabled: forSegmentAtIndex:Unselected
YESsetEnabled: forSegmentAtIndex:Selected
Segmented Control
Segmented Control Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
216
Selected
Whether segment identified by Segment is selected.
Use selectedSegmentIndex to select a segment.
Selection
Unselected
Selected
Content Offset
The offset from the segment origin at which to draw the content of the segment identified by Segment.
Access: setContentOffset:forSegmentAtIndex:.
Segmented Control
Segmented Control Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
217
Slider Attributes Inspector Reference
Value
Minimum
The bottom of the range of values the slider can have.
Access: minimumValue.
Maximum
The top of the range of values the slider can have.
Access: maximumValue.
Current
The numeric value of the slider.
Access: value.
Images
Min Image
The image displayed on the minimum side of the slider.
Access: minimumValueImage.
Max Image
The image displayed on the maximum side of the slider.
Access: maximumValueImage.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
218
Slider
Appearance
Min Track Tint
The color of the track on the minimum side of the slider.
Access: minimumTrackTintColor.
Max Track Tint
The color of the track on the maximum side of the slider.
Access: maximumTrackTintColor.
Thumb Tint
The color of the slider thumb.
Access" thumbTintColor.
Update Events
Continuous
Whether the slider continuously sends update events as the user moves the thumb.
You can receive updated values on the slider by responding to the value changed event
UIControlEventValueChanged. In continuous updates, the slider sends multiple value changed events as
the user moves the thumb. In noncontinuous updates, the slider sends one value changed event when the
user releases the thumb.
ArgumentMethodSelection
NOcontinuousUnselected
YEScontinuousSelected
Slider
Slider Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
219
Stepper Attributes Inspector Reference
Value
Minimum
The minimum value of the stepper.
Access: minimumValue.
Maximum
The maximum value of the stepper.
Access: maximumValue.
Current
The value of the stepper.
Access: value.
Step
The amount by which the stepper increments or decrements its value.
Access: stepValue.
Behavior
Autorepeat
Whether the stepper keeps incrementing or decrementing its value while either of its buttons is held down.
ArgumentMethodSelection
NOautorepeatUnselected
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
220
Stepper
ArgumentMethodSelection
YESautorepeatSelected
Continuous
Whether the stepper continuously sends update events as either of its buttons is held down.
In continuous updates the stepper sends update events as the user holds the button. In noncontinuous updates
the stepper sends one update event when the user releases the button.
ArgumentMethodSelection
NOcontinuousUnselected
YEScontinuousSelected
Wraps
Whether the stepper wraps around the minimum and maximum values.
ArgumentMethodSelection
NOwrapsUnselected
YESwrapsSelected
Stepper
Stepper Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
221
Switch Attributes Inspector Reference
Appearance and State
State
Whether the switch is on or off.
ArgumentMethodSelection
YESonOn
NOonOff
On Tint
The color of the switch when it is on.
Access: onTintColor.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
222
Switch
Tab Bar Attributes Inspector Reference
Appearance
Tint
The color of the tab bar.
Access: tintColor.
Image Tint
The color for the image of tab bar items when selected at runtime.
Access: selectedImageTintColor.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
223
Tab Bar
Tab Bar Item Attributes Inspector Reference
Appearance
Badge
The tab bar item badge.
Access: badgeValue.
Identifier
The tab bar item icon.
ArgumentMethodSelection
Custom
UITabBarSystemItemMoreinitWithTabBarSystemItem: tag:More
UITabBarSystemItemFavoritesinitWithTabBarSystemItem: tag:Favorites
UITabBarSystemItemFeaturedinitWithTabBarSystemItem: tag:Featured
UITabBarSystemItemTopRatedinitWithTabBarSystemItem: tag:Top Rated
UITabBarSystemItemRecentsinitWithTabBarSystemItem: tag:Recents
UITabBarSystemItemContactsinitWithTabBarSystemItem: tag:Contacts
UITabBarSystemItemHistoryinitWithTabBarSystemItem: tag:History
UITabBarSystemItemBookmarksinitWithTabBarSystemItem: tag:Bookmarks
UITabBarSystemItemSearchinitWithTabBarSystemItem: tag:Search
UITabBarSystemItemDownloadsinitWithTabBarSystemItem: tag:Downloads
UITabBarSystemItemMostRecentinitWithTabBarSystemItem: tag:Most Recent
UITabBarSystemItemMostViewedinitWithTabBarSystemItem: tag:Most Viewed
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
224
Tab Bar Item
Table View Attributes Inspector Reference
Appearance
Style
The basic appearance of the table view.
ArgumentMethodSelection
UITableViewStylePlainstylePlain
UITableViewStyleGroupedstyleGrouped
Separator
Separator Style
The style for table view cells used as separators.
ArgumentMethodSelection
UITableViewCellSeparatorStyleNoneseparatorStyleNone
UITableViewCellSeparatorStyleSingleLineseparatorStyleSingle Line
UITableViewCellSeparatorStyleSingle-
LineEtched
separatorStyleSingle Line Etched
Separator Color
The color for table view cells used as separators.
Access: separatorColor
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
225
Table View
Behavior
Selection
The type of selection the table view allows.
Access: allowsSelection allowsMultipleSelection
CodeSelection
table_view.allowsSelection = NONo Selection
table_view.allowsSelection = YESSingle Selection
table_view.allowsMultipleSelection = YESMultiple Selection
Editing
The type of selection the table view allows in editing mode.
Access: allowsSelectionDuringEditing allowsMultipleSelectionDuringEditing
CodeSelection
table_view.allowsSelectionDuringEditing = NONo Selection During Editing
table_view.allowsSelectionDuringEditing = YESSingle Selection During Editing
table_view.allowsMultipleSelectionDuringEditing
= YES
Multiple Selection During Editing
Show Selection on Touch
This item appears to be nonoperational.
Table Index
Index Row Limit
This item appears to be nonoperational.
Table View
Table View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
226
Table View Cell Attributes Inspector Reference
Style
The Image property appears in this group only when Style is Basic, Right Detail, or Subtitle.
Style
The appearance and layout of the table view cell labels.
For the Custom style, your custom subclass of UITableViewCell determines the appearance of the table
view cell.
Access: reuseIdentifier
ArgumentMethodSelection
Custom
UITableViewCellStyleDefaultinitWithStyle: reuseIdentifier:Basic
UITableViewCellStyleValue1initWithStyle: reuseIdentifier:Right Detail
UITableViewCellStyleValue2initWithStyle: reuseIdentifier:Left Detail
UITableViewCellStyleSubtitleinitWithStyle: reuseIdentifier:Subtitle
Image
The image for the table view cell content.
Access: image
Cell Reuse
Identifier
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
227
Table View Cell
Identifies the table view cell for cell reuse.
Access: initWithStyle:reuseIdentifier:reuseIdentifier
Appearance
Selection
Whether and how the table view cell indicates that it is selected.
ArgumentMethodSelection
UITableViewCellSelectionStyleNoneselectionStyleNone
UITableViewCellSelectionStyleBlueselectionStyleBlue
UITableViewCellSelectionStyleGrayselectionStyleGray
Accessory
The accessory view type for the table view cell in the Normal state.
The three states of a table view cell are: Normal, Editing, and Delete Confirmation (Cell State Mask
Constants).
ArgumentMethodSelection
UITableViewCellAccessoryNoneaccessoryTypeNone
UITableViewCellAccessoryDisclosureIndicatoraccessoryTypeDisclosure Indicator
UITableViewCellAccessoryDetail-
DisclosureButton
accessoryTypeDetail Disclosure
UITableViewCellAccessoryCheckmarkaccessoryTypeCheckmark
Editing Acc.
The accessory view type of the table view cell in the Editing state.
The three states of a table view cell are: Normal, Editing, and Delete Confirmation (Cell State Mask
Constants).
Table View Cell
Table View Cell Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
228
ArgumentMethodSelection
UITableViewCellAccessoryNoneeditingAccessoryTypeNone
UITableViewCellAccessoryDisclosure-
Indicator
editingAccessoryTypeDisclosure Indicator
UITableViewCellAccessoryDetail-
DisclosureButton
editingAccessoryTypeDetail Disclosure
UITableViewCellAccessoryCheckmarkeditingAccessoryTypeCheckmark
Indentation and Behavior
Indentation
Level
The table view cell indentation level.
Access: indentationLevel
Width
The width in points of each level of indentation.
Access: indentationWidth
Indent While Editing
Whether to indent the table view cell background when the table view cell is in the Editing state.
ArgumentMethodSelection
NOshouldIndentWhileEditingUnselected
YESshouldIndentWhileEditingSelected
Shows Re-order Controls
Whether the table view cell shows the reordering control.
ArgumentMethodSelection
NOshowsReorderControlUnselected
Table View Cell
Table View Cell Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
229
ArgumentMethodSelection
YESshowsReorderControlSelected
Table View Cell
Table View Cell Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
230
Text View Attributes Inspector Reference
Text
Text
Text Type
The type of the text view text.
Selection
Plain
Attributed
Text Type: Plain
Use this group to configure the text view plain text.
Text
The text view plain text.
Access: text
Color
The color of the text view plain text.
Access: textColor
Font
The font of the text view plain text.
Access: font
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
231
Text View
Alignment
The alignment of the text view plain text.
ArgumentMethodSelection
NSTextAlignmentLefttextAlignmentLeft
NSTextAlignmentCentertextAlignmentCenter
NSTextAlignmentCentertextAlignmentRight
Text Type: Attributed
Use this group set the characteristics of the selected text in Attributed Text.
To set alignment and other layout characteristics of part of the attributed text in code, you need to create an
attributed string with the desired characteristics and assign it to attributedText.
Attributed Text Layout
The alignment and other layout characteristics of the selected attributed text.
Selection
Left
Center
Right
Justified
Natural
Text Color
Background Color
More
Font
The font of the selected attributed text.
Attributed Text
Text View
Text View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
232
The the text view attributed text.
Access: attributedText
Allows Editing Attributes
Whether the user can change characteristics of the attributed text.
ArgumentMethodSelection
NOallowsEditingTextAttributesUnselected
YESallowsEditingTextAttributesSelected
Behavior
Editable
Whether the user can edit text view text.
ArgumentMethodSelection
NOeditableUnselected
YESeditableSeleted
Data Detection
Detection
Links
Whether the text view detects hyperlinks in the text.
Access: dataDetectorTypes
CodeSelection
text_view.dataDetectorTypes &= ~UIDataDetectorTypeLinkUnselected
text_view.dataDetectorTypes |= UIDataDetectorTypeLinkSelected
Addresses
Text View
Text View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
233
Whether the text view detects addresses in the text.
Access: dataDetectorTypes
CodeSelection
text_view.dataDetectorTypes &= ~UIDataDetectorTypeAddressUnselected
text_view.dataDetectorTypes |= UIDataDetectorTypeAddressesSelected
Phone Numbers
Whether the view detects phone numbers in the text.
Access: dataDetectorTypes
CodeSelection
text_view.dataDetectorTypes &= ~UIDataDetectorTypePhoneNumberUnselected
text_view.dataDetectorTypes |= UIDataDetectorTypePhoneNumberSelected
Events
Whether the text view detects calendar events in the text.
Access: dataDetectorTypes
CodeSelection
text_view.dataDetectorTypes &= ~UIDataDetectorTypeCalendarEventUnselected
text_view.dataDetectorTypes |= UIDataDetectorTypeCalendarEventSelected
Text Input and Keyboard
Capitalization
Whether and when the keyboard activates the Shift key while the user types text.
ArgumentMethodSelection
UITextAutocapitalizationTypeNoneautocapitalizationTypeNone
Text View
Text View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
234
ArgumentMethodSelection
UITextAutocapitalizationTypeWordsautocapitalizationTypeWords
UITextAutocapitalizationTypeSentencesautocapitalizationTypeSentences
UITextAutocapitalization-
TypeAllCharacters
autocapitalizationTypeAll Characters
Correction
Whether to auto-correct text the text user types.
ArgumentMethodSelection
UITextAutocorrectionTypeDefaultautocorrectionTypeDefault
UITextAutocorrectionTypeNoautocorrectionTypeNo
UITextAutocorrectionTypeYesautocorrectionTypeYes
Keyboard
The keyboard that appears on text input.
ArgumentMethodSelection
UIKeyboardTypeDefaultkeyboardTypeDefault
UIKeyboardTypeASCIICapablekeyboardTypeASCII Capable
UIKeyboardTypeNumbersAnd-
Punctuation
keyboardTypeNumbers and Punctuation
UIKeyboardTypeURLautocorrectionTypeURL
UIKeyboardTypeNumberPadkeyboardTypeNumber Pad
UIKeyboardTypePhonePadkeyboardTypePhone Pad
UIKeyboardTypeNamePhonePadkeyboardTypeName Phone Pad
UIKeyboardTypeEmailAddresskeyboardTypeE-mail Address
Appearance
The keyboard to use for text input.
Text View
Text View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
235
ArgumentMethodSelection
UIKeyboardAppearanceDefaultkeyboardAppearanceDefault
UIKeyboardAppearanceAlertkeyboardAppearanceAlert
Return Key
The type of the keyboard Return key.
The type of the Return key specifies the Return key title.
ArgumentMethodSelection
UIReturnKeyDefaultreturnKeyTypeDefault
UIReturnKeyGoreturnKeyTypeGo
UIReturnKeyGooglereturnKeyTypeGoogle
UIReturnKeyJoinreturnKeyTypeJoin
UIReturnKeyNextreturnKeyTypeNext
UIReturnKeyRoutereturnKeyTypeRoute
UIReturnKeySearchreturnKeyTypeSearch
UIReturnKeySendreturnKeyTypeSend
UIReturnKeyYahooreturnKeyTypeYahoo
UIReturnKeyDonereturnKeyTypeDone
UIReturnKeyEmergencyCallreturnKeyTypeEmergency Call
Auto-enable Return Key
Whether the user can press the Return key after entering text.
ArgumentMethodSelection
NOenablesReturnKeyAutomaticallyUnselected
YESenablesReturnKeyAutomaticallySelected
Text View
Text View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
236
Secure
Whether the text view hides entered text.
ArgumentMethodSelection
NOsecureTextEntryUnselected
YESsecureTextEntrySelected
Text View
Text View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
237
Toolbar Attributes Inspector Reference
Appearance
Style
The basic appearance of the toolbar.
ArgumentMethodSelection
UIBarStyleDefaultbarStyleDefault
UIBarStyleBlackbarStyleBlack Opaque
UIBarStyleBlackTranslucentbarStyleBlack Translucent
Tint
The color of the toolbar.
Access: tintColor.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
238
Toolbar
View Attributes Inspector Reference
Layout and Tagging
Mode
How the view presents its content when the view size changes.
ArgumentMethodSelection
UIViewContentModeScaleToFillcontentModeScale to Fill
UIViewContentModeScaleAspectFitcontentModeAspect Fit
UIViewContentModeScaleAspectFillcontentModeAspect Fill
UIViewContentModeRedrawcontentModeRedraw
UIViewContentModeCentercontentModeCenter
UIViewContentModeTopcontentModeTop
UIViewContentModeBottomcontentModeBottom
UIViewContentModeLeftcontentModeLeft
UIViewContentModeRightcontentModeRight
UIViewContentModeTopLeftcontentModeTop Left
UIViewContentModeTopRightcontentModeTop Right
UIViewContentModeBottomLeftcontentModeBottom Left
UIViewContentModeBottomRightcontentModeBottom Right
Tag
The view tag.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
239
View
Access: tag.
Events
Interaction
User Interaction Enabled
Whether the view processes touch and keyboard events.
ArgumentMethodSelection
NOuserInteractionEnabledUnselected
YESuserInteractionEnabledSelected
Multiple Touch
Whether the view processes multiple touch events.
ArgumentMethodSelection
NOmultipleTouchEnabledUnselected
YESmultipleTouchEnabledSelected
Appearance
Alpha
The view transparency.
The range of values is from 0.0 and 1.0:
● 0.0 makes the view completely transparent.
● 1.0 makes the view completely opaque.
Access: alpha.
Background
The view background color.
View
View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
240
Access: backgroundColor.
Drawing and Sizing
Drawing
Opaque
Whether the drawing system treats the view as opaque.
ArgumentMethodSelection
NOopaqueUnselected
YESopaqueSelected
Hidden
Whether the view is hidden.
ArgumentMethodSelection
NOhiddenUnselected
YEShiddenSelected
Clears Graphics Context
Whether the view clears its bounds before drawing.
ArgumentMethodSelection
NOclearsContextBeforeDrawingUnselected
YESclearsContextBeforeDrawingSelected
Clip Subviews
Whether subviews are clipped to the view bounds.
If the view alpha value (alpha) is 1.0, drawing performance can be improved by indicating that the view is
opaque.
View
View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
241
ArgumentMethodSelection
NOclipsToBoundsUnselected
YESclipsToBoundsSelected
Autoresize Subviews
Whether the view resizes subviews when the view size changes.
If the view alpha value (alpha) is 1.0, drawing performance can be improved by indicating that the view is
opaque.
ArgumentMethodSelection
NOautoresizesSubviewsUnselected
YESautoresizesSubviewsSelected
Sizing
Stretching
The rectangle that identifies stretchable area of the view.
The values for the rectangle specifiers (X, Y, Width, and Height) are in the range 0.0 to 1.0. For example, to
make only half of the view stretchable, specify the rectangle (0.0, 0.0, 0.5, 1.0).
Access: contentStretch.
View
View Attributes Inspector Reference
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
242
Web View Attributes Inspector
Data Detection and Sizing
Scaling
Scales Page to Fit
Whether the view resizes the webpage to fit the view bounds.
ArgumentMethodSelection
NOautoresizesSubviewsUnselected
YESautoresizesSubviewsSelected
Detection
Links
Whether the view detects hyperlinks in the webpage.
Access: dataDetectorTypes.
CodeSelection
web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypeLinkUnselected
web_view.dataDetectorTypes |= UIDataDetectorTypeLinkSelected
Addresses
Whether the view detects addresses in the webpage.
Access: dataDetectorTypes.
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
243
Web View
CodeSelection
web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypeAddressUnselected
web_view.dataDetectorTypes |= UIDataDetectorTypeAddressesSelected
Phone Numbers
Whether the view detects phone numbers in the webpage.
CodeSelection
web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypePhoneNumberUnselected
web_view.dataDetectorTypes |= UIDataDetectorTypePhoneNumberSelected
Events
Whether the view detects calendar events in the webpage.
CodeSelection
web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypeCalendarEventUnselected
web_view.dataDetectorTypes |= UIDataDetectorTypeCalendarEventSelected
Web View
Web View Attributes Inspector
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
244
This table describes the changes to UIKit User Interface Catalog.
NotesDate
New document that describes the views and controls in UIKit, drawing
from the human interface guidelines for more depth.
2013-06-10
2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information.
245
Document Revision History
Apple Inc.
Copyright © 2013 Apple Inc.
All rights reserved.
No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in any
form or by any means, mechanical, electronic,
photocopying, recording, or otherwise, without
prior written permission of Apple Inc., with the
following exceptions: Any person is hereby
authorized to store documentation on a single
computer for personal use only and to print
copies of documentation for personal use
provided that the documentation contains
Apple’s copyright notice.
No licenses, express or implied, are granted with
respect to any of the technology described in this
document. Apple retains all intellectual property
rights associated with the technology described
in this document. This document is intended to
assist application developers to develop
applications only for Apple-labeled computers.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
Apple, the Apple logo, Cocoa, GarageBand, iPad,
iPhone, iTunes, Numbers, Pages, Safari, and Xcode
are trademarks of Apple Inc., registered in the
U.S. and other countries.
Genius is a service mark of Apple Inc., registered
in the U.S. and other countries.
X Window System is a trademark of the
Massachusetts Institute of Technology.
iOS is a trademark or registered trademark of
Cisco in the U.S. and other countries and is used
under license.
Even though Apple has reviewed this document,
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS
DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED
“AS IS,” AND YOU, THE READER, ARE ASSUMING THE
ENTIRE RISK AS TO ITS QUALITY AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES RESULTING FROM ANY DEFECT OR
INACCURACY IN THIS DOCUMENT, even if advised of
the possibility of such damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE
ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer,
agent, or employee is authorized to make any
modification, extension, or addition to this warranty.
Some states do not allow the exclusion or limitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusion may not apply to you. This warranty gives
you specific legal rights, and you may also have other
rights which vary from state to state.

More Related Content

PDF
iOS 7 Human Interface Guidelines
PDF
iOS humaninterfaceguidelines
PDF
Apple iOS 7 Preview
PPTX
iPhone SE
PDF
Introducing Apple New iPad(iPad 4th generation)
PDF
iOS 7 Human Interface Guidelines
PPT
Avoid software project horror stories - check the reality value of the estima...
PDF
Inversion of Control
iOS 7 Human Interface Guidelines
iOS humaninterfaceguidelines
Apple iOS 7 Preview
iPhone SE
Introducing Apple New iPad(iPad 4th generation)
iOS 7 Human Interface Guidelines
Avoid software project horror stories - check the reality value of the estima...
Inversion of Control

Viewers also liked (20)

PDF
The Social Shift Fund - Presentation
PDF
A possible cure 2014 may9
PDF
Big data meets evm (submitted).pptx
PPTX
Fix you some bad estimation habits
PDF
Systems Engineering in One Picture
PDF
Principles of program governance
PDF
Architectured Centered Design
PDF
PMI chapter meeting (v4)
PDF
Immutable Principles Of Project Management (V7 Final Cmu)
PPTX
Pedir lo mismo de diferentes maneras
PDF
Physical Percent Complete - june 2010 (6)
PPTX
Customer Intelligence & Social Media
PDF
Risk management processes
PDF
Cure for cost and schedule growth
DOCX
Universidades
PDF
Establishing the performance measurement baseline (pmi fort worth)(v4)
PDF
PM Chapter on Agile IT Project Management Methods
PDF
UX for Lean Startups Sep 15
PDF
4 PM Anti-Patterns
PPTX
search.com or Google: Why we suck at naming products and companies (PCA13)
The Social Shift Fund - Presentation
A possible cure 2014 may9
Big data meets evm (submitted).pptx
Fix you some bad estimation habits
Systems Engineering in One Picture
Principles of program governance
Architectured Centered Design
PMI chapter meeting (v4)
Immutable Principles Of Project Management (V7 Final Cmu)
Pedir lo mismo de diferentes maneras
Physical Percent Complete - june 2010 (6)
Customer Intelligence & Social Media
Risk management processes
Cure for cost and schedule growth
Universidades
Establishing the performance measurement baseline (pmi fort worth)(v4)
PM Chapter on Agile IT Project Management Methods
UX for Lean Startups Sep 15
4 PM Anti-Patterns
search.com or Google: Why we suck at naming products and companies (PCA13)
Ad

Similar to UIKit User Interface Catalog (iOS 7) (20)

PDF
Ui kit uicatalog_ios apple developer
PDF
UIKit User Interface Catalog ios7
PDF
ASP.NET ONLINE TRAINING
PPTX
SFDC UI - Introduction to Visualforce
DOCX
SAP CRM TECHNICAL TRAINING | ONLINE TRAINING FOR SAP CRM
ODP
TYPO3 Housekeeping
PDF
View controllerp gforios
PDF
Angularjs
PDF
Safari Web Content Guide
PDF
SAP CRM TECHNICAL ONLINE TRAINING | SAP CRM TECHNICAL TRAINING
PDF
SAP CRM TECHNICAL TRAINING | LEARN SAP CRM TECHNICAL
PDF
SAP CRM TECHNICAL ONLINE TRAINING | SAP CRM TECHNICAL
PDF
SAP CRM TECHNICAL ONLINE TRAINING | SAP CRM TECHNICAL
PDF
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL CLASSES
PDF
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL
PDF
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL COURSE
PDF
SAP CRM TECHNICAL ONLINE | SAP CRM LEARN ONLINE IN USA
PDF
SAP CRM TECHNICAL TRAINING | SAP CRM TECHNICAL ONLINE TRAINING
PDF
SAP CRM TECHNICAL TRAINING | LEARN SAP CRM TECHNICAL ONLINE
PDF
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL
Ui kit uicatalog_ios apple developer
UIKit User Interface Catalog ios7
ASP.NET ONLINE TRAINING
SFDC UI - Introduction to Visualforce
SAP CRM TECHNICAL TRAINING | ONLINE TRAINING FOR SAP CRM
TYPO3 Housekeeping
View controllerp gforios
Angularjs
Safari Web Content Guide
SAP CRM TECHNICAL ONLINE TRAINING | SAP CRM TECHNICAL TRAINING
SAP CRM TECHNICAL TRAINING | LEARN SAP CRM TECHNICAL
SAP CRM TECHNICAL ONLINE TRAINING | SAP CRM TECHNICAL
SAP CRM TECHNICAL ONLINE TRAINING | SAP CRM TECHNICAL
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL CLASSES
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL COURSE
SAP CRM TECHNICAL ONLINE | SAP CRM LEARN ONLINE IN USA
SAP CRM TECHNICAL TRAINING | SAP CRM TECHNICAL ONLINE TRAINING
SAP CRM TECHNICAL TRAINING | LEARN SAP CRM TECHNICAL ONLINE
SAP CRM TECHNICAL TRAINING | ONLINE SAP CRM TECHNICAL
Ad

Recently uploaded (20)

PPT
Machine printing techniques and plangi dyeing
PDF
Quality Control Management for RMG, Level- 4, Certificate
PPTX
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
PDF
Interior Structure and Construction A1 NGYANQI
PPTX
Fundamental Principles of Visual Graphic Design.pptx
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PPT
pump pump is a mechanism that is used to transfer a liquid from one place to ...
PPTX
An introduction to AI in research and reference management
PPTX
building Planning Overview for step wise design.pptx
PPT
UNIT I- Yarn, types, explanation, process
PPTX
12. Community Pharmacy and How to organize it
PPTX
HPE Aruba-master-icon-library_052722.pptx
PDF
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
PDF
Urban Design Final Project-Context
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PPTX
areprosthodontics and orthodonticsa text.pptx
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PDF
High-frequency high-voltage transformer outline drawing
PPTX
Tenders & Contracts Works _ Services Afzal.pptx
Machine printing techniques and plangi dyeing
Quality Control Management for RMG, Level- 4, Certificate
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
Interior Structure and Construction A1 NGYANQI
Fundamental Principles of Visual Graphic Design.pptx
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
pump pump is a mechanism that is used to transfer a liquid from one place to ...
An introduction to AI in research and reference management
building Planning Overview for step wise design.pptx
UNIT I- Yarn, types, explanation, process
12. Community Pharmacy and How to organize it
HPE Aruba-master-icon-library_052722.pptx
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
Urban Design Final Project-Context
DOC-20250430-WA0014._20250714_235747_0000.pptx
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
areprosthodontics and orthodonticsa text.pptx
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
High-frequency high-voltage transformer outline drawing
Tenders & Contracts Works _ Services Afzal.pptx

UIKit User Interface Catalog (iOS 7)

  • 2. Contents Views 13 About Views 14 Configuring Views 16 Setting View Content 16 Specifying View Behavior 17 Customizing View Appearance 18 Using Auto Layout with Views 20 Making Views Accessible 21 Debugging Views 21 Action Sheets 22 Configuring Action Sheets 22 Setting Action Sheet Content Programmatically 22 Specifying Action Sheet Behavior Programmatically 23 Using Auto Layout with Action Sheets 24 Making Action Sheets Accessible 24 Internationalizing Action Sheets 24 Debugging Action Sheets 24 Elements Similar to an Action Sheet 25 Activity Indicators 26 Configuring Activity Indicators 26 Setting Activity Indicator Values 26 Specifying Activity Indicator Behavior 27 Customizing Activity Indicator Appearance 27 Using Auto Layout with Activity Indicators 28 Making Activity Indicators Accessible 28 Internationalizing Activity Indicators 29 Debugging Activity Indicators 29 Elements Similar to an Activity Indicator 29 Alert Views 30 Configuring Alert Views 30 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 2
  • 3. Setting Alert View Content Programmatically 31 Specifying Alert View Behavior Programmatically 32 Customizing Alert View Appearance 33 Using Auto Layout with Alert Views 33 Making Alert Views Accessible 33 Internationalizing Alert Views 33 Debugging Alert Views 34 Elements Similar to an Alert View 34 Collection Views 35 Configuring Collection Views 36 Setting Collection View Content 36 Specifying Collection View Behavior 37 Customizing Collection View Appearance 39 Using Auto Layout with Collection Views 40 Making Collection Views Accessible 40 Internationalizing Collection Views 41 Elements Similar to a Collection View 41 Image Views 42 Configuring Image Views 43 Setting Image View Content 43 Specifying Image View Behavior 44 Customizing Image View Appearance 44 Using Auto Layout with Image Views 45 Making Image Views Accessible 46 Internationalizing Image Views 46 Debugging Image Views 46 Elements Similar to an Image View 47 Labels 49 Configuring Labels 50 Setting Label Content 51 Specifying Label Behavior 51 Customizing Label Appearance 52 Using Auto Layout with Labels 53 Making Labels Accessible 53 Internationalizing Labels 54 Debugging Labels 54 Elements Similar to a Label 54 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 3 Contents
  • 4. Navigation Bars 55 Configuring Navigation Bars 56 Setting Navigation Bar Content 56 Specifying Navigation Bar Behavior 57 Customizing Navigation Bar Appearance 58 Using Auto Layout with Navigation Bars 60 Making Navigation Bars Accessible 60 Internationalizing Navigation Bars 60 Debugging Navigation Bars 60 Elements Similar to a Navigation Bar 61 Picker Views 62 Configuring Picker Views 62 Setting Picker View Content Programmatically 62 Specifying Picker View Behavior 63 Customizing Picker View Appearance 63 Using Auto Layout with Picker Views 63 Making Picker Views Accessible 64 Internationalizing Picker Views 64 Debugging Picker Views 64 Elements Similar to a Picker View 64 Progress Views 65 Configuring Progress Views 65 Setting Progress View Value 66 Customizing Progress View Appearance 66 Using Auto Layout with Progress Views 67 Making Progress Views Accessible 68 Internationalizing Progress Views 68 Elements Similar to a Progress View 68 Scroll Views 69 Configuring Scroll Views 70 Setting Scroll View Content 70 Specifying Scroll View Behavior 70 Customizing Scroll View Appearance 73 Using Auto Layout with Scroll Views 74 Making Scroll Views Accessible 74 Internationalizing Scroll Views 74 Elements Similar to a Scroll View 74 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 4 Contents
  • 5. Search Bars 75 Configuring Search Bars 76 Setting Search Bar Content 77 Specifying Search Bar Behavior 78 Customizing Search Bar Appearance 79 Using Auto Layout with Search Bars 80 Making Search Bars Accessible 81 Internationalizing Search Bars 81 Debugging Navigation Bars 81 Elements Similar to a Search Bar 82 Tab Bars 83 Configuring Tab Bars 83 Specifying Tab Bar Content 84 Specifying Tab Bar Behavior 84 Customizing Tab Bar Appearance 84 Using Auto Layout with Tab Bars 86 Making Tab Bars Accessible 86 Internationalizing Tab Bars 86 Elements Similar to a Tab Bar 87 Table Views 88 Configuring Table Views 91 Setting Table Content 92 Specifying Table View Behavior 93 Customizing Table View Appearance 95 Using Auto Layout with Table Views 97 Making Table Views Accessible 97 Internationalizing Table Views 97 Elements Similar to a Table View 97 Text Views 98 Configuring Text Views 99 Setting Text View Content 99 Specifying Text View Behavior 100 Customizing Text View Appearance 101 Using Auto Layout with Text Views 102 Making Text Views Accessible 102 Internationalizing Text Views 102 Debugging Text Views 102 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 5 Contents
  • 6. Elements Similar to a Text View 103 Toolbars 104 Configuring Toolbars 105 Setting Toolbar Content 105 Specifying Toolbar Behavior 106 Customizing Toolbar Appearance 107 Using Auto Layout with Toolbars 109 Making Toolbars Accessible 109 Internationalizing Toolbars 110 Debugging Toolbars 110 Elements Similar to a Toolbar 110 Web Views 111 Configuring Web Views 112 Setting Web View Content Programmatically 112 Specifying Web View Behavior 112 Customizing Web View Appearance 113 Using Auto Layout with Web Views 113 Making Web Views Accessible 113 Internationalizing Web Views 113 Debugging Web Views 113 Elements Similar to a Web View 114 Controls 115 About Controls 116 Configuring Controls 117 Setting Control Content 117 Specifying Control Behavior 117 Customizing Control Appearance 119 Using Auto Layout with Controls 120 Making Controls Accessible 121 Buttons 123 Configuring Buttons 124 Setting Button Content 125 Specifying Button Behavior 125 Customizing Button Appearance 126 Using Auto Layout with Buttons 129 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 6 Contents
  • 7. Making Buttons Accessible 129 Internationalizing Buttons 130 Debugging Buttons 130 Elements Similar to a Button 130 Date Pickers 131 Configuring Date Pickers 132 Setting Date Picker Values 132 Specifying Date Picker Behavior 133 Customizing Date Picker Appearance 134 Using Auto Layout with Date Pickers 134 Making Date Pickers Accessible 135 Internationalizing Date Pickers 135 Debugging Date Pickers 135 Elements Similar to a Date Picker 136 Page Controls 137 Configuring Page Controls 138 Specifying Page Control Values 138 Specifying Page Control Behavior 138 Customizing Page Control Appearance 139 Using Auto Layout with Page Controls 140 Making Page Controls Accessible 140 Internationalizing Text Fields 141 Debugging Page Controls 141 Elements Similar to a Page Control 141 Segmented Controls 142 Configuring Segmented Controls 142 Setting Segmented Control Values 143 Specifying Segmented Control Behavior 143 Customizing Segmented Control Appearance 145 Using Auto Layout with Segmented Controls 147 Making Segmented Controls Accessible 147 Internationalizing Segmented Controls 147 Debugging Segmented Controls 147 Elements Similar to a Segmented Control 148 Sliders 149 Configuring Sliders 150 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 7 Contents
  • 8. Setting Slider Values 150 Specifying Slider Behavior 151 Customizing Slider Appearance 151 Using Auto Layout with Sliders 153 Making Sliders Accessible 154 Internationalizing Sliders 154 Debugging Sliders 154 Elements Similar to a Slider 155 Steppers 156 Configuring Steppers 156 Setting Stepper Values 157 Specifying Stepper Behavior 157 Customizing Stepper Appearance 158 Using Auto Layout with Steppers 159 Making Steppers Accessible 159 Internationalizing Steppers 160 Elements Similar to a Stepper 160 Switches 161 Configuring Switches 161 Setting Switch Value 162 Specifying Switch Behavior Programmatically 162 Customizing Switch Appearance 162 Using Auto Layout with Switches 163 Making Switches Accessible 163 Internationalizing Switches 164 Debugging Switches 164 Elements Similar to a Switch 164 Text Fields 165 Configuring Text Fields 165 Setting Text Field Content 166 Specifying Text Field Behavior 166 Customizing Text Field Appearance 168 Using Auto Layout with Text Fields 169 Making Text Fields Accessible 169 Internationalizing Text Fields 170 Elements Similar to a Text Field 170 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 8 Contents
  • 9. Attributes Inspector Reference 171 Activity Indicator View 173 Activity Indicator View Attributes Inspector Reference 173 Appearance and Behavior 173 Bar Button Item 175 Bar Button Item Attributes Inspector Reference 175 Appearance 175 Bar Item 178 Bar Item Attributes Inspector Reference 178 Appearance, Behavior, and Tagging 178 Button 179 Button Attributes Inspector Reference 179 Type 179 Appearance 179 Behavior 182 Edge Insets 184 Collection Reusable View 185 Collection Reusable View Attributes Inspector Reference 185 Cell Reuse 185 Collection View 186 Collection View Attributes Inspector Reference 186 Layout, Scrolling, Header, and Footer 186 Collection View Cell 188 Collection View Cell Attributes Inspector Reference 188 Cell Reuse 188 Control 189 Control Attributes Inspector Reference 189 Layout 189 Behavior 190 Date Picker 191 Date Picker Attributes Inspector Reference 191 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 9 Contents
  • 10. Functionality 191 Date 192 Count Down Timer 193 Image View 194 Image View Attributes Inspector Reference 194 Images 194 Behavior 194 Label 195 Label Attributes Inspector Reference 195 Text and Behavior 195 Text Baseline and Line Breaks 197 Text Sizing 198 Text Highlight and Shadow 199 Navigation Bar 200 Navigation Bar Attributes Inspector Reference 200 Appearance 200 Navigation Item 201 Navigation Item Attributes Inspector Reference 201 PropertyGroup 201 Page Control 202 Page Control Attributes Inspector Reference 202 Behavior and Pages 202 Appearance 203 Picker View 204 Picker View Attributes Inspector Reference 204 Behavior 204 Progress View 205 Progress View Attributes Inspector Reference 205 Appearance and Progress 205 Scroll View 206 Scroll View Attributes Inspector Reference 206 Appearance 206 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 10 Contents
  • 11. Scroll Indicators and Scrolling 206 Scroll Bounce 208 Zooming 209 Events and Zoom Bounce 209 Search Bar 211 Search Bar Attributes Inspector Reference 211 Search Term and Captions 211 Appearance 211 Capabilities 212 Scope Titles 213 Text Input 213 Segmented Control 215 Segmented Control Attributes Inspector Reference 215 Appearance and Behavior 215 Segment Appearance and Behavior 216 Slider 218 Slider Attributes Inspector Reference 218 Value 218 Images 218 Appearance 219 Update Events 219 Stepper 220 Stepper Attributes Inspector Reference 220 Value 220 Behavior 220 Switch 222 Switch Attributes Inspector Reference 222 Appearance and State 222 Tab Bar 223 Tab Bar Attributes Inspector Reference 223 Appearance 223 Tab Bar Item 224 Tab Bar Item Attributes Inspector Reference 224 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 11 Contents
  • 12. Appearance 224 Table View 225 Table View Attributes Inspector Reference 225 Appearance 225 Behavior 226 Table Index 226 Table View Cell 227 Table View Cell Attributes Inspector Reference 227 Style 227 Cell Reuse 227 Appearance 228 Indentation and Behavior 229 Text View 231 Text View Attributes Inspector Reference 231 Text 231 Behavior 233 Data Detection 233 Text Input and Keyboard 234 Toolbar 238 Toolbar Attributes Inspector Reference 238 Appearance 238 View 239 View Attributes Inspector Reference 239 Layout and Tagging 239 Events 240 Appearance 240 Drawing and Sizing 241 Sizing 242 Web View 243 Web View Attributes Inspector 243 Scaling 243 Detection 243 Document Revision History 245 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 12 Contents
  • 13. ● “About Views” (page 14) ● “Action Sheets” (page 22) ● “Activity Indicators” (page 26) ● “Alert Views” (page 30) ● “Collection Views” (page 35) ● “Image Views” (page 42) ● “Labels” (page 49) ● “Navigation Bars” (page 55) ● “Picker Views” (page 62) ● “Progress Views” (page 65) ● “Scroll Views” (page 69) ● “Search Bars” (page 75) ● “Tab Bars” (page 83) ● “Table Views” (page 88) ● “Text Views” (page 98) ● “Toolbars” (page 104) ● “Web Views” (page 111) 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 13 Views
  • 14. Important: This is a preliminary document for an API or technology in development. Although this document has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only by registered members of the applicable Apple Developer program. Apple is supplying this confidential information to help you plan for the adoption of the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be tested with final operating system software and final documentation. Newer versions of this document may be provided with future seeds of the API or technology. You can think of views as building blocks that you use to construct your user interface. Rather than use one view to present all of your content, you often use several views to build a view hierarchy. These views range from simple buttons and text labels to more complex views such as table views, picker views, and scroll views. Each view in the hierarchy presents a particular portion of your user interface and is generally optimized for a specific type of content. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 14 About Views
  • 15. All views in UIKit are subclasses of the base class UIView. For example, UIKit has views specifically for presenting images, text, and other types of content. In places where the predefined views do not provide what you need, you can also define custom views and manage the drawing and event handling yourself. Views allow the user to: ● Experience app content ● Navigate within an app Implementation: Views are implemented in the UIView class and discussed in UIView Class Reference. About Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 15
  • 16. Configuring Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting View Content Use the Mode (contentMode) field to specify how a view lays out its content when its bounds change. This property is often used to implement resizable controls. Instead of redrawing the contents of the view every time its bounds change, you can use this property to specify that you want to scale the contents or pin them to a particular spot on the view. The Tag (tag) field serves as an integer that you can use to identify view objects in your app. About Views Configuring Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 16
  • 17. Specifying View Behavior By default, the User Interaction Enabled (userInteractionEnabled) checkbox is selected, which means that user events—such as touch and keyboard—are delivered to the view normally. When the checkbox is unselected, events intended for the view are ignored and removed from the event queue. The Multiple Touch (multipleTouchEnabled) checkbox is unselected by default, which means that the view receives only the first touch event in a multi-touch sequence. When selected, the view receives all touches associated with a multitouch sequence. Views have a number of properties related to drawing behavior: ● The Opaque (opaque) checkbox tells the drawing system how it should treat the view. If selected, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If unselected, the drawing system composites the view normally with other content. You should always disable this checkbox if your view is fully or partially transparent. ● If the Hidden (hidden) checkbox is selected, the view disappears from its window and does not receive input events. ● When the Clears Graphics Context (clearsContextBeforeDrawing) checkbox is selected, the drawing buffer is automatically cleared to transparent black before the view is drawn. This behavior ensures that there are no visual artifacts left over when the view’s contents are redrawn. ● Selecting the Clip Subviews (clipsToBounds) checkbox causes subviews to be clipped to the bounds of the view. If unselected, subviews whose frames extend beyond the visible bounds of the view are not clipped. ● When the Autoresize Subviews (autoresizesSubviews) checkbox is selected, the view adjusts the size of its subviews when its bounds change. About Views Configuring Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 17
  • 18. Customizing View Appearance Setting View Background Color and Alpha Adjusting the Alpha (alpha) field changes the transparency of the view as a whole. This value can range from 0.0 (transparent) to 1.0 (opaque). Setting a view’s alpha value does not have an effect on embedded subviews. Use the Background (backgroundColor) field to select a color to fill in the entire frame of the view. The background color appears underneath all other content in the view. Using Appearance Proxies You can use an appearance proxy to set particular appearance properties for all instances of a view in your application. For example, if you want all sliders in your app to have a particular minimum track tint color, you can specify this with a single message to the slider’s appearance proxy. There are two ways to customize appearance for objects: for all instances and for instances contained within an instance of a container class. ● To customize the appearance of all instances of a class, use appearance to get the appearance proxy for the class. [[UISlider appearance] setMinimumTrackTintColor:[UIColor greenColor]]; ● To customize the appearances for instances of a class when contained within an instance of a container class, or instances in a hierarchy, you use appearanceWhenContainedIn: to get the appearance proxy for the class. [[UISlider appearanceWhenContainedIn:[UIView class], nil] setMinimumTrackTintColor:[UIColor greenColor]]; About Views Configuring Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 18
  • 19. Note: You cannot use the appearance proxy with the tintColor property on UIView. For more information on using tintColor, see “Adjusting View Tint Color” (page 19). Adjusting View Tint Color Views have a tintColor property that specifies the color of key elements within the view. Each subclass of UIView defines its own appearance and behavior for tintColor. For example, this property determines the color of the outline, divider, and glyphs on a stepper: The tintColor property is a quick and simple way to skin your app with a custom color. Setting a tint color for a view automatically sets that tint color for all of its subviews. However, you can manually override this property for any of those subviews and its decendants. In other words, each view inherits its superview’s tint color if its own tint color is nil. If the highest level view in the view heirarchy has a nil valur for tint color, it defaults to the system blue color. Using Template Images In iOS 7, you can choose to treat any of the images in your app as a template—or stencil—image. When you elect to treat an image as a template, the system ignores the image’s color information and creates an image stencil based on the alpha values in the image (parts of the image with an alpha value of less than 1.0 get treated as completely transparent). This stencil can then be recolored using tintColor to match the rest of your user interface. By default, an image (UIImage) is created with UIImageRenderingModeAutomatic. If you have UIImageRenderingModeAutomatic set on your image, it will be treated as template or original based on its context. Certain UIKit elements—including navigation bars, tab bars, toolbars, segmented controls—automatically treat their foreground images as templates, although their background images are treated as original. Other elements—such as image views and web views—treat their images as originals. If you want your image to always be treated as a template regardless of context, set UIImageRenderingModeAlwaysTemplate; if you want your image to always be treated as original, set UIImageRenderingModeAlwaysOriginal. To specify the rendering mode of an image, first create a standard image, and then call the imageWithRenderingMode: method on that image. UIImage *myImage = [UIImage imageNamed:@"myImageFile.png"]; myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; About Views Configuring Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 19
  • 20. Using Auto Layout with Views The Auto Layout system allows you to define layout constraints for user interface elements, such as views and controls. Constraints represent relationships between user interface elements. You can create Auto Layout constraints by selecting the appropriate element or group of elements and selecting an option from the menu in the bottom right corner of Xcode’s Interface Builder. Auto layout contains two menus of constraints: pin and align. The Pin menu allows you to specify constraints that define some relationship based on a particular value or range of values. Some apply to the control itself (width) while others define relationships between elements (horizontal spacing). The following tables describes what each group of constraints in the Auto Layout menu accomplishes: PurposeConstraint Name Sets the width or height of a single element. Sets the horizontal or vertical spacing between exactly two elements. Sets the spacing from one or more elements to the leading, trailing, top, or bottom of their container view. Leading and trailing are the same as left and right in English, but the UI flips when localized in a right-to-left environment. Sets the widths or heights of two or more elements equal to each other. Aligns the left, right, top, or bottom edges of two or more elements. Aligns two or more elements according to their horizontal centers, vertical centers, or bottom baselines. Note that baselines are different from bottom edges. These values may not be defined for certain elements. Aligns the horizontal or vertical centers of one or more elements with the horizontal or vertical center of their container view. About Views Using Auto Layout with Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 20
  • 21. The “Constant” value specified for any Pin constraints (besides Widths/Heights Equally) can be part of a “Relation.” That is, you can specify whether you want the value of that constraint to be equal to, less than or equal to, or greater than or equal to the value. For more information, see Cocoa Auto Layout Guide. Making Views Accessible To enhance the accessibility information for an item, select the object on the storyboard and open the Accessibility section of the Identity inspector. For more information, see Accessibility Programming Guide for iOS. Debugging Views When debugging issues with views, watch for this common pitfall: Setting conflicting opacity settings. You should not set the opaque property to YES if your view has an alpha value of less than 1.0. About Views Making Views Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 21
  • 22. Action sheets display a set of buttons representing several alternative choices to complete a task initiated by the user. For example, when the user taps the Share button in an app’s toolbar, an action sheet appears offering a list of choices, such as Email, Print, and so on. Action sheets allow the user to: ● Quickly select from a list of actions ● Confirm or cancel an action Implementation: Action sheets are implemented in the UIActionSheet class and discussed in the UIActionSheet Class Reference. Configuring Action Sheets Action sheets are created, initialized, and configured in code, typically residing in a view controller implementation file. You cannot create or manipulate action sheets in Interface Builder. Rather, an action sheet appears over an existing view, interrupting its presentation, and it requires the user to dismiss it by tapping one of its buttons (or tapping outside the action sheet on iPad). The chosen action is handled by the action sheet’s delegate. Setting Action Sheet Content Programmatically When you create an action sheet object from the UIActionSheet class, you can initialize its most important properties with one method, initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:. Depending on your app’s needs, that single message may be enough to configure a fully functional action sheet object, as shown in the following code. Once you have created the action sheet object, send it a show... message, such as showInView: to display the action sheet. UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Note" 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 22 Action Sheets
  • 23. otherButtonTitles:nil]; Although the first parameter of the initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles: method enables you to provide a title for an action sheet, iOS human interface guidelines recommend that you do not use a title. As described in iOS human interface guidelines, you should include a Cancel button with action sheets displayed on iPhone and with those displayed on iPad over an open popover. Otherwise on iPad, action sheets are displayed within a popover, and the user can cancel the action sheet by tapping outside the popover, in which case you do not need to include a Cancel button. To create a Cancel button, pass a non-nil value for the cancelButtonTitle: parameter of the initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles: method. A Cancel button created in this way is positioned at the bottom of the action sheet. When your action sheet presents a potentially destructive choice, you should include a destructive button by passing a non-nil value for the destructiveButtonTitle: parameter of the initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles: method. A destructive button created in this way is automatically colored red and positioned at the top of the action sheet. Specifying Action Sheet Behavior Programmatically You can choose to present an action sheet so that it originates from a toolbar, tab bar, button bar item, from a view, or from a rectangle within a view. On iPhone, because the action sheet slides up from the bottom of a view and covers the width of the screen, most apps use showInView:. On iPad, however, action sheets appear within a popover whose arrow points to the control the user tapped to invoke the choices presented by the action sheet. So, showFromRect:inView:animated: and showFromBarButtonItem:animated: are most useful on iPad. To handle the choices presented by your action sheet, you must designate a delegate to handle the button’s action, and the delegate must conform to the UIActionSheetDelegate protocol. You designate the delegate with the delegate parameter when you initialize the action sheet object. The delegate must implement the actionSheet:clickedButtonAtIndex: message to respond when the button is tapped. For example, the following code shows an implementation that simply logs the title of the button that was tapped. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { Action Sheets Configuring Action Sheets 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 23
  • 24. NSLog(@"The %@ button was tapped.", [actionSheet buttonTitleAtIndex:buttonIndex]); } Using Auto Layout with Action Sheets The layout of action sheets is handled for you. You cannot create Auto Layout constraints between an action sheet and another user interface element. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Action Sheets Accessible Action sheets are accessible by default. Accessibility for action sheets primarily concerns button titles. If VoiceOver is activated, it speaks the word “alert” when an action sheet is shown, then speaks its title if set (although iOS human interface guidelines recommend against titling action sheets). As the user taps a button in the action sheet, VoiceOver speaks its title and the word “button.” For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Action Sheets To internationalize an action sheet, you must provide localized translations of the button titles. Button size may change depending on the language and locale. For more information, see Internationalization Programming Topics. Debugging Action Sheets When debugging issues with action sheets, watch for this common pitfall: Action Sheets Using Auto Layout with Action Sheets 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 24
  • 25. Not testing localizations. Be sure to test the action sheets in your app with the localizations you intend to ship. In particular, button titles can truncate if they are longer in localizations other than the one in which you designed your user interface. Following the HI guideline to give buttons short, logical titles helps to ameliorate this potential problem, but localization testing is also required. Elements Similar to an Action Sheet The following elements provide similar functionality to an action sheet: ● Alert View. Use an alert view to convey important information about an app or the device, interrupting the user and requiring them to stop what they’re doing to choose an action or dismiss the alert. For more information, see “Alert Views” (page 30). ● Modal View. Use a modal view (that is, the view controller uses a modal presentation style) when users initiate a self-contained subtask in the context of their workflow or another task. For more information, see UIViewController Class Reference. Action Sheets Elements Similar to an Action Sheet 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 25
  • 26. An activity indicator is a spinning wheel that indicates a task is in the midst of being processed. If an action takes a noticeable and indeterminate amount of time to process—such as a CPU-intensive task or connecting to a network—you should display an activity indicator to give assurance to the user that your app is not stalled or frozen. Activity indicators allow the user to: ● Receive feedback that the system is processing information Implementation: Activity indicators are implemented in the UIActivityIndicatorView class and discussed in the UIActivityIndicatorView Class Reference. Configuring Activity Indicators Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Activity Indicator Values An activity indicator is indeterminate, and has no starting or ending values associated with it. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 26 Activity Indicators
  • 27. Specifying Activity Indicator Behavior The Animating (isAnimating) box is unchecked by default; checking it causes the activity indicator to start animating. This is the equivalent of calling the startAnimating method. Select the Hides When Stopped (hidesWhenStopped) field in the Attributes Inspector for your activity indicator to disappear when the animation ends. When you call the startAnimating and stopAnimating methods, the activity indicator automatically shows and hides onscreen. This way, you won’t have to worry about displaying a stationary activity indicator. Customizing Activity Indicator Appearance You can customize the appearance of an activity indicator by setting the properties depicted below. To customize the appearance of all activity indicators in your app, use the appearance proxy (for example, [UIActivityIndicatorView appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Setting Activity Indicator Style The Style (activityIndicatorViewStyle) field represents the predefined style of the activity indicator. Use the style to specify one of two default colors: white or gray. You can also select a larger size for your indicator using the “Large White” style option. Activity Indicators Configuring Activity Indicators 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 27
  • 28. The Color (color) field allows you to specify a custom color for your indicator. This property takes precedence over any color set using the Style field. However, if your style is set to Large White, your activity indicator appears a larger size. Make sure your indicator is set to a different style option if you want to use the small indicator. Using Auto Layout with Activity Indicators You can create Auto Layout constraints between an activity indicator and other UI elements. Typically, activity indicators appear before a label or centered within a view. To align with a label, constrain Bottom Edges and Horizontal Space to the label with the standard value. To center within a view, add the Horizontal Center in Container and Vertical Center in Container constraints. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Activity Indicators Accessible Activity indicators are accessible by default. The default accessibility trait for an activity indicator is User Interaction Enabled. If you have a label next to your activity indicator that describes the processing task in more detail, you might want to disable its accessibility with the isAccessibilityElement property so VoiceOver reads the label instead. Otherwise, VoiceOver reads “In progress” while the activity indicator is animating, and “Progress halted” while it is not. VoiceOver will read only elements that are visible onscreen. If you enable the hidesWhenStopped property, VoiceOver might abruptly stop speaking when the animation finishes. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Activity Indicators Using Auto Layout with Activity Indicators 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 28
  • 29. Internationalizing Activity Indicators Activity indicators have no special properties related to internationalization. However, if you use an activity indicator with a label, make sure you provide localized strings for the label. For more information, see Internationalization Programming Topics. Debugging Activity Indicators When debugging issues with activity indicators, watch for this common pitfall: Specifying conflicting appearance settings. The color property takes precedence over any color set using the activityIndicatorViewStyle property. However, if your style is set to Large White, your activity indicator appears a larger size with whatever custom color you set. Make sure your indicator is set to a different style option if you want to use the small indicator. Elements Similar to an Activity Indicator The following element provides similar functionality to an activity indicator: Progress View. A class that represents a progress bar. Use this class instead of an activity indicator when your task takes a determinate amount of time. For more information, see “Progress Views” (page 65). Activity Indicators Internationalizing Activity Indicators 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 29
  • 30. Alert views display a concise and informative alert message to the user. Alert views convey important information about an app or the device, interrupting the user and requiring them to stop what they’re doing to choose an action or dismiss the alert. For example, iOS uses alerts to warn the user that battery power is running low, so they can connect a power adapter before their workflow is interrupted. An alert view appears on top of app content, and must be manually dismissed by the user before he can resume interaction with the app. Alert views allow the user to: ● Be immediately informed of critical information ● Make a decision about a course of action Implementation: Alert views are implemented in the UIAlertView class and discussed in the UIAlertView Class Reference. Configuring Alert Views Alert views are created, initialized, and configured in code, typically residing in a view controller implementation file. You cannot create or manipulate alert views in Interface Builder. Rather, an alert view floats over an existing view to interrupt its presentation, and it requires the user to dismiss it. If the alert view contains a custom button enabling the user to choose an alternative action, rather than simply dismissing the alert, that action is handled by the alert view’s delegate. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 30 Alert Views
  • 31. Setting Alert View Content Programmatically When setting alert view content, you can control the number of buttons, their titles, displayed text, and inclusion of one or two text fields, one of which can be a secure text-input field. When you create an alert view object from the UIAlertView class, you can initialize its most important properties with one method, initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:. Depending on your app’s needs, that single message may be enough to configure a fully functional alert object, as shown in the following code. After you have created the alert object, send it a show message to display the alert. UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"This is the message." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [theAlert show]; Every alert has a Cancel button so that the user can dismiss the alert. You can add additional, custom buttons to enable the user to perform some other action related to the alert, such as rectifying the problem the alert warned about. Although you can add multiple custom buttons to an alert, iOS Human Interface Guidelines recommend that you limit alerts to two buttons, and consider using an action sheet instead if you need more. To add a titled custom button to an alert, send it an addButtonWithTitle: message. Alternatively, you can pass the custom button title, followed by a comma and nil terminator, with the otherButtonTitles: parameter when you initialize the alert view object. Alert Views Configuring Alert Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 31
  • 32. Optionally, an alert can contain one or two text fields, one of which can be a secure text-input field. You add text fields to an alert after it is created by setting its alertViewStyle property to one of the styles specified by the UIAlertViewStyle constants. The alert view styles can specify no text field (the default style), one plain text field, one secure text field (which displays a bullet character as each character is typed), or two text fields (one plain and one secure) to accommodate a login identifier and password. Specifying Alert View Behavior Programmatically If your alert has a custom button, you must designate a delegate to handle the button’s action, and the delegate must conform to the UIAlertViewDelegate protocol. You designate the delegate with the delegate parameter when you initialize the alert view object. The delegate must implement the alertView:clickedButtonAtIndex: message to respond when the custom button is tapped; otherwise, your custom buttons do nothing. For example, the following code shows an implementation that simply logs the title of the button that was tapped: - (void)alertView:(UIAlertView *)theAlert clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"The %@ button was tapped.", [theAlert buttonTitleAtIndex:buttonIndex]); } In the delegate method alertView:clickedButtonAtIndex:, depending on which button the user tapped, you can retrieve the values of text fields in your alert view with the textFieldAtIndex: method. if (theAlert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput) { NSLog(@"The login field says %@, and the password is %@.", [theAlert textFieldAtIndex:0].text, [theAlert textFieldAtIndex:1].text); } Alert Views Configuring Alert Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 32
  • 33. The alert view is automatically dismissed after the alertView:clickedButtonAtIndex: delegate method is invoked. Optionally, you can implement the alertViewCancel: method to take the appropriate action when the system cancels your alert view. An alert view can be canceled at any time by the system—for example, when the user taps the Home button. If the delegate does not implement the alertViewCancel: method, the default behavior is to simulate the user clicking the cancel button and closing the view. Customizing Alert View Appearance You cannot customize the appearance of alert views. Using Auto Layout with Alert Views The layout of alert views is handled for you. You cannot create Auto Layout constraints between an alert view and another user interface element. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Alert Views Accessible Alert views are accessible by default. Accessibility for alert views pertains to the alert title, alert message, and button titles. If VoiceOver is activated, it speaks the word “alert” when an alert is shown, then speaks its title followed by its message if set. As the user taps a button, VoiceOver speaks its title and the word “button.” As the user taps a text field, VoiceOver speaks its value and “text field” or “secure text field.” For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Alert Views To internationalize an alert view, you must provide localized translations of the alert title, message, and button titles. Screen metrics and layout may change depending on the language and locale. For more information, see Internationalization Programming Topics. Alert Views Using Auto Layout with Alert Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 33
  • 34. Debugging Alert Views When debugging issues with sliders, watch for this common pitfall: Not testing localizations. Be sure to test the alert views in your app with the localizations you intend to ship. In particular, button titles can truncate if they are longer in localizations other than the one in which you designed your user interface. Following the HI guideline to give buttons short, logical titles helps to ameliorate this potential problem, but localization testing is also required. Elements Similar to an Alert View The following elements provide similar functionality to an alert view: ● Action Sheet. Present an action sheet when users tap a button in a toolbar, giving them choices related to the action they’ve initiated. For more information, see “Action Sheets” (page 22). ● Modal View. Present a modal view (that is, the view controller uses a modal presentation style) when users initiate a subtask in the context of their workflow or another task. For more information, see UIViewController Class Reference. Alert Views Debugging Alert Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 34
  • 35. A collection view displays an ordered collection of data items using standard or custom layouts. Similar to a table view, a collection view gets data from your custom data source objects and displays it using a combination of cell, layout, and supplementary views. A collection view can display items in a grid or in a custom layout that you design. Regardless of the layout style you choose, a collection view is best suited to display nonhierarchical, ordered data items. Collection views allow the user to: ● View a catalog of variably sized items, optionally sorted into multiple sections ● Add to, rearrange, and edit a collection of items ● Choose from a frequently changing display of items Implementation: ● Collection views are implemented in the UICollectionView class and discussed in the UICollectionView Class Reference. ● Collection view cells are implemented in the UICollectionViewCell class and discussed in the UICollectionViewCell Class Reference. ● Collection reusable views are implemented in the UICollectionReusableView class and discussed in the UICollectionReusableView Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 35 Collection Views
  • 36. Configuring Collection Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Collection View Content Cells present the main content of your collection view. The job of a cell is to present the content for a single item from your data source object. Each cell must be an instance of the UICollectionViewCell class, which you may subclass as needed to present your content. Cell objects provide inherent support for managing their own selection and highlight state, although some custom code must be written to actually apply a highlight to a cell. A UICollectionViewCell object is a specific type of reusable view that you use for your main data items. To manage the visual presentation of data, a collection view works with many related classes, such as UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionReusableView, UICollectionViewCell, UICollectionViewLayout, and UICollectionViewLayoutAttributes. Collection views enforce a strict separation between the data being presented and the visual elements used for presentation. Your app is solely responsible for managing the data via your custom data source objects. (To learn how to create these objects, see “Designing Your Data Objects” in Collection View Programming Guide Collection Views Configuring Collection Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 36
  • 37. for iOS.) Your app also provides the view objects used to present that data. The collection view takes your views and—with the help of a layout object, which specifies placement and other visual attributes—does all the work of displaying them onscreen. To display content onscreen in an efficient way, a collection view uses the following reusable view objects: ● Cell. Represents one data item. ● Supplementary view. Represents information related to the data items, such as a section header or footer. ● Decoration view. Represents purely decorative content that’s not part of your data, such as a background image. Because a collection view works with these and other objects to determine the visual presentation of your data, configuring a collection view in Interface Builder means that you need to configure some objects separately. ● Items. The number of different types of data for which you define distinct cell objects. If your app works with only one type of data item—regardless of the total number of data items you display—set this value to 1. ● Accessories. The existence of a header or footer view for each section (this property isn’t available for custom layouts). Select Section Header or Section Footer as appropriate. In Collection Reusable View Attributes inspector—which governs supplementary views, decoration views, and cells—you can set the Identifier (identifier) field. Enter the ID you use in your code to identify the reusable cell, decoration, or supplementary view object. Specifying Collection View Behavior There are several behaviors you can support in your collection view. For example, you might want to allow users to: ● Select one or more items ● Insert, delete, and reorder items or sections ● Edit an item Collection Views Configuring Collection Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 37
  • 38. By default, a collection view detects when the user taps a specific cell and it updates the cell’s selected or highlighted properties as appropriate. You can write code that configures a collection view to support multiple-item selection or that draws the selected or highlighted states yourself. To learn how to support multiple selection or custom selection states, see “Managing the Visual State for Selections and Highlights” in Collection View Programming Guide for iOS. To support insertion, deletion, or reordering of cells in a collection view, you make changes to your data source and then tell the collection view to redisplay the content. By default, a collection view animates the insertion, deletion, or movement of a single item; if you want to animate these changes for multiple items at once, you use code blocks to batch the update. To learn how animate multiple changes to a collection view, see “Inserting, Deleting, and Moving Sections and Items” in Collection View Programming Guide for iOS. To let users move an item or items by dragging, you also need to incorporate a custom gesture recognizer. (To learn how to do this, see “Manipulating Cells and Views” in Collection View Programming Guide for iOS.) If you support editing for an item, the collection view automatically displays the Edit menu when it detects a long-press gesture on a specific cell. To learn how to support editing in a collection view, see “Showing the Edit Menu for a Cell” in Collection View Programming Guide for iOS. When configuring cells and supplementary views in a storyboard, you do so by dragging the item onto your collection view and configuring it there. This creates a relationship between the collection view and the corresponding cell or view. For cells, drag a collection view cell from the object library and drop it onto your collection view. Set the custom class and the collection reusable view identifier of your cell to appropriate values. Whether the user is selecting or deselecting a cell, the cell’s selected state is always the last thing to change. Taps in a cell always result in changes to the cell’s highlighted state first. Only after the tap sequence ends and any highlights applied during that sequence are removed, does the selected state of the cell change. When designing your cells, you should make sure that the visual appearance of your highlights and selected state do not conflict in unintended ways. When the user performs a long-tap gesture on a cell, the collection view attempts to display an Edit menu for that cell. The Edit menu can be used to cut, copy, and paste cells in the collection view. If you’re working with the UICollectionViewFlowLayout class, you can use the Attributes inspector to set the “Scroll Direction” (scrollDirection) field to Horizontal or Vertical. Note that this property isn’t available for custom layouts. Collection Views Configuring Collection Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 38
  • 39. Customizing Collection View Appearance Specifying Collection View Layout A collection view relies on a layout object to define the layout of its cells, supplementary views, and decoration views. The Layout field determines the layout of the cells. The default value is Flow, which refers to the layout defined by the UICollectionViewFlowLayout class. If you provide a custom layout class, choose Custom instead. To learn more about creating a custom layout class, see Collection View Programming Guide for iOS. Setting Collection View Background To use a custom background for a collection view, you can specify a view that's positioned underneath all of the other content and sized automatically to fill the entire bounds of the collection view. You can set this value using the backgroundView property. Because this background view doesn’t scroll with the collection view’s content, it’s not an appropriate way to display a decorative background such as the appearance of wooden shelves. Setting Collection View Cell Background To use a custom background for a single collection view cell, you can specify a view that’s positioned behind the cell’s content view and that fills the cell’s bounds. You can set this value using the backgroundView property. You can also specify a custom selected background by providing a view that’s displayed above the cell’s background view—and behind the content view—when the user selects the cell. Set this value using the selectedBackgroundView property. Adjusting Collection View Spacing In the Collection View Flow Layout Size Inspector, you can set size values (in points) for the layout object to use when laying out cells and supplementary views. For spacing between cells you can set the following Min Spacing values: Collection Views Configuring Collection Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 39
  • 40. ● For Cells. The minimum space to maintain between cells on one line. ● For Lines. The minimum space to maintain between lines of cells. Adjusting Collection View Cell Padding To add padding around cells so that space appears above, below, or on either side of the cells in a section, use the “Section Insets” fields in the Collection View Flow Layout Size Inspector. Specifying nonzero inset values reduces the amount of space available for laying out cells, which lets you limit the number of cells that can appear on one row or the number of rows that can appear in one section. The insets you can specify are: ● Top. The space to add between the bottom of the header view and the top of the first line of cells. ● Bottom. The space to add between the bottom last line of cells and the top of the footer ● Left. The space to add between the left edge of the cells and the left edge of the collection view. ● Right. The space to add between the right edge of the cells and the right edge of the collection view. Using Auto Layout with Collection Views You can create Auto Layout constraints between a collection view and other user interface elements. You can create any type of constraint for a collection view besides a baseline constraint. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Collection Views Accessible The data items in a collection view are accessible by default when they are represented by standard UIKit objects, such as UILabel and UITextField. When a collection view changes its onscreen layout, it posts the UIAccessibilityLayoutChangedNotification notification. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Collection Views Using Auto Layout with Collection Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 40
  • 41. Internationalizing Collection Views For more information, see Internationalization Programming Topics. Elements Similar to a Collection View The following elements provide similar functionality to a collection view: ● Table View. A scrolling view that displays data items in a single-column list. For more information, see “Table Views” (page 88). ● Scroll View. A scrolling view that displays content without support for any specific layout or ordering scheme. For more information, see “Scroll Views” (page 69). Collection Views Internationalizing Collection Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 41
  • 42. An image view displays an image or an animated sequence of images. An image view lets you efficiently draw an image (such as a JPEG or PNG file) or an animated series of images onscreen, scaling the images automatically to fit within the current size of the view. Image views can optionally display a different image or series of images whenever the view is highlighted. Image views support the same file formats as the UIImage class—TIFF, JPEG, PNG, Windows bitmap (bmp), Windows icon (ico), Windows cursor (cur), and X Window System bitmap (xbm) formats. Image views allow the user to: ● View images within an app Implementation: Image views are implemented in the UIImageView class and discussed in the UIImageView Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 42 Image Views
  • 43. Configuring Image Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. In addition, image views provide significant programmatic customization by modifying properties on the view objects and properties on whatever image object you have loaded into the view. Setting Image View Content If you are displaying a single image, most image views require minimal configuration beyond setting the image. If you are displaying an animated series of images, you must also configure the animation settings. When you first use an image view object to display a single image, you can select an image to display using the Image (image) field in the Attributes Inspector. If you did not choose an image in the Attributes Inspector, you must set the initial image by calling initWithImage: or by setting the image property to a UIImage object that describes the image you want to display. If you want to show a different image when the view is highlighted, you can specify this information in the Highlighted (highlightedImage) field. Alternatively, either call initWithImage:highlightedImage: when you initialize the image or set the highlightedImage property to the alternative image. If you want your image view to display an animated sequence of images, you must do this programmatically. Because you cannot specify an array of images in the Attributes Inspector, you must write some code to tell the image view which images to use. To do this, set the animationImages property to an array of UIImage objects in the order in which they should be shown. Optionally set the highlightedAnimationImages property if you want to show a different animation while the view is highlighted. Image Views Configuring Image Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 43
  • 44. Important: All images associated with a UIImageView object should have the same scale value. If your application uses images with different scales, they may render incorrectly. Specifying Image View Behavior Use the Highlighted (highlighted) checkbox to specify whether the view should show the standard or highlighted image or image sequence. You can change the image view’s state at any time. If you are using an image sequence, you can instead configure the animation behavior programmatically: ● Set the animationDuration to the desired animation period (in seconds). By default, this property is computed based on the number of images at 30 frames per second. ● Set the animationRepeatCount to limit the number of iterations through the set of images. By default, this property has a value of zero, which means that the animation repeats forever. You start the animation by calling startAnimating. Customizing Image View Appearance You cannot customize the appearance of an image view directly. However, you can determine how images appear in the view by setting properties at the UIImage and UIView levels. Setting View Content Mode The view’s contentMode property specifies how the image should be scaled and aligned within the view. It is recommended (but not required) that you use images that are all the same size. If the images are different sizes, each will be adjusted to fit separately based on this mode. Creating Images The image’s capInsets, leftCapWidth, and topCapHeight properties specify the width and height of a central portion of the image that should be scaled differently than the border areas (outside that central portion). The top and bottom border areas are tiled horizontally. The left and right border areas are tiled vertically. The corners are displayed as-is. Additionally, the image’s alignmentRectInsets property specifies portions of the image to ignore for alignment purposes (such as shadow and glow effects). Image Views Configuring Image Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 44
  • 45. You can create images for images views in a number of ways, including: ● Using the imageWithAlignmentRectInsets: method, which returns a derived image with nonzero alignment insets. ● Using the resizableImageWithCapInsets: or resizableImageWithCapInsets:resizingMode: methods, which return a derived static image with nonzero cap insets. The image’s resizingMode property indicates whether the image should be scaled or tiled. ● Using the animatedResizableImageNamed:capInsets:duration: or animatedResizableImageNamed:capInsets:resizingMode:duration: methods, which return a derived animated image with nonzero cap insets. These methods cannot be set after the image is created or loaded. Customizing Image Transparency and Alpha Blending Transparency of an image view is defined by properties of both the underlying image and the view as follows: ● If the view’s Opaque (opaque) flag is set, the image is alpha blended with the background color of the view, and the view itself is opaque. The view’s Alpha (alpha) setting is ignored. ● If the view’s Opaque (opaque) flag is not set, the alpha channel for each pixel (or 1.0 if the image has no alpha channel) is multiplied by the view’s Alpha (alpha) setting, and the resulting value determines the transparency for that pixel. Important: It is computationally expensive to perform alpha compositing of non-opaque image views containing images with alpha channels. If you are not intentionally using the image alpha channel or the view’s Alpha setting, you should set the Opaque flag to improve performance. See the last bullet point of “Debugging Image Views” (page 46) for more information. Using Auto Layout with Image Views You can create Auto Layout constraints between a image view and other user interface elements. You can create any type of constraint for a image view besides a baseline constraint. You generally want the image view to fill the full width of your screen. To ensure that this happens correctly on all devices and orientations, you can create Leading Space to Superview and Trailing Space to Superview constraints, and set both values equal to 0. This will ensure that the image view remains pinned to the edges of the device screen. Image Views Using Auto Layout with Image Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 45
  • 46. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Image Views Accessible Image views are accessible by default. The default accessibility traits for a image view are Image and User Interaction Enabled. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Image Views Internationalization of image views is automatic if your view displays only static images loaded from your app bundle. If you are loading images programmatically, you are at least partially responsible for loading the correct image. ● For resources in your app bundle, you do this by specifying the name in the attributes inspector or by calling the imageNamed: class method on UIImage to obtain the localized version of each image. ● For images that are not in your app bundle, your code must do the following: 1. Determine which image to load in a manner specific to your app, such as providing a localized string that contains the URL. 2. Load that image by passing the URL or data for the correct image to an appropriate UIImage class method, such as imageWithData: or imageWithContentsOfFile:. Tip: Screen metrics and layout may also change depending on the language and locale, particularly if the internationalized versions of your images have different dimensions. Where possible, you should try to make minimize dimension differences in internationalized versions of image resources. For more information, see Internationalization Programming Topics. Debugging Image Views When debugging issues with image views, watch for these common pitfalls: Image Views Making Image Views Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 46
  • 47. ● Not loading your image with the correct method. If you are loading an image from your app bundle, use imageNamed:. If you are loading an image from a file (with a full path or URL), use imageWithContentsOfFile:. ● Not making animated image frames the same size. This helps you avoid having to deal with scaling, tiling, or positioning differences between frames. ● Not using a consistent scale value for all animated image frames. Mixing images with different scale factors may produce undefined behavior. ● Doing custom drawing in a subclass of an image view. The UIImageView class is optimized to draw its images to the display. UIImageView does not call the drawRect: method of its subclasses. If your subclass needs to include custom drawing code, you should subclass the UIView class instead. ● Not enabling event handling in subclasses if you need it. New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object. ● Not providing prescaled images where possible. For example, if you expect certain large images to be frequently displayed in a scaled-down thumbnail view, you might consider keeping the scaled-down images in a thumbnail cache. Scaling the image is a relatively expensive operation. ● Not limiting image size. Consider prescaling or tiling large images. The MVCNetworking sample code project (QImageScrollView.m) demonstrates how to determine what model of iOS device your software is running on. You can then use that information to help you determine the image dimension thresholds to use when scaling or tiling. ● Not disabling alpha blending except where needed. Unless you are intentionally working with images that contain transparency (drawing UI elements, for example), you should generally mark the view as opaque by selecting the Opaque checkbox in the Attributes Inspector, or setting the opaque property on the view itself. For views that are not opaque, the device must perform a lot of unnecessary computation if alpha blending is enabled and the image contains an alpha channel. This performance impact is further magnified if you are using Core Animation shadows, because the shape of the shadow is then based on the contents of the view, and must be dynamically computed. To learn more about how alpha blending works, see “Customizing Image Transparency and Alpha Blending” (page 45). Elements Similar to an Image View The following elements provide similar functionality to a web view: Image Views Elements Similar to an Image View 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 47
  • 48. ● Button. You can set the background image of a button control (of type UIButtonTypeCustom). For more information, see “Buttons” (page 123). ● Scroll View. An image view typically scales content up or down to fit the dimensions of the view. If you need to display an image with user-controlled zooming and scaling, you should place that image view inside a scroll view. For more information, see “Scroll Views” (page 69). ● Custom Views. If you create a custom subclass of UIView, you can programmatically draw images inside its drawRect: method. (For maximum performance, you should do this only when absolutely necessary.) For more information, see “About Views” (page 14). Image Views Elements Similar to an Image View 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 48
  • 49. A label displays static text. Labels are often used in conjunction with controls to describe their intended purpose, such as explaining which value a button or slider affects. Labels allow the user to: ● Understand the purpose of controls in an app ● Receive instructions or context in an app Implementation: Labels are implemented in the UILabel class and discussed in the UILabel Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 49 Labels
  • 50. Configuring Labels Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Labels Configuring Labels 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 50
  • 51. Setting Label Content Set label content using the Label Text (text and attributedText) field in the Attributes Inspector. Both properties get set whether you specified the value of the Text field to be plain or attributed. For more information about attributed text, see “Specifying Text Appearance” (page 52). By default, a label is a single line. To create a multiline label, increase the value of the Lines (numberOfLines) field. Specifying Label Behavior You can specify whether a label is enabled or highlighted using the Enabled (enabled) and Highlighted (highlighted) checkboxes in the Attributes Inspector. The Autoshrink (adjustsFontSizeToFitWidth) field is used to specify the manner in which font size will be reduced with the label’s bounding rectangle. The Fixed Font Size option is the equivalent of setting adjustsFontSizeToFitWidth to NO, meaning that font size will not adjust. Select the Minimum Font Scale (minimumScaleFactor) option to specify the smallest multiplier for the current font size that the font can scale down to, and the Minimum Font Size (minimumFontSize) option to specify the smallest font size that the font can scale down to. Labels Configuring Labels 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 51
  • 52. Select the Tighten Letter Spacing (adjustsLetterSpacingToFitWidth) checkbox if you want the spacing between letters to be adjusted to fit the string within the label’s bounding rectangle. The Baselines (baselineAdjustment) field determines how to adjust the position of text in cases when the text must be drawn using a different font size than the one originally specified. For example, with the Align Baselines option, the position of the baseline remains fixed at its initial location while the text appears to move toward that baseline. Similarly, selecting the None option makes it appear as if the text is moving upwards toward the top-left corner of the bounding box. Use the Line Breaks (lineBreakMode) field to specify the technique to use for wrapping and truncating the label’s text if it exceeds a single line. Note that if this property is set to a value that causes text to wrap to another line, do not set the adjustsFontSizeToFitWidth or adjustsLetterSpacingToFitWidth property to YES. Customizing Label Appearance You can customize the appearance of a label by setting the properties depicted below. To customize the appearance of all labels in your app, use the appearance proxy (for example, [UILabel appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Specifying Text Appearance Labels can have one of two types of text: plain or attributed. Plain text supports a single set of formatting attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports multiple sets of attributes that apply to individual characters or ranges of characters in the string. Labels Configuring Labels 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 52
  • 53. Specifying Highlighted Appearance By default, the highlighted appearance of a label is no different than that of its normal control state. However, you can create a different look for your label when it’s in the UIControlStateHighlighted state by modifying its color in the Highlighted (highlightedTextColor) field. Setting a Text Shadow You can set a color for your label’s shadow using the Shadow (shadowColor) field in the Attributes Inspector. If you want to change how far the shadow is drawn from the button text, you can adjust the shadow offset. You can customize the offset for both dimensions using the Shadow Offset (shadowOffset) fields. Using Auto Layout with Labels You can create Auto Layout constraints between a label and other user interface elements. You can create any type of constraint for a label. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Labels Accessible Labels are accessible by default. The default accessibility trait for a label are Static Text and User Interaction Enabled. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Labels Using Auto Layout with Labels 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 53
  • 54. Internationalizing Labels For more information, see Internationalization Programming Topics. Debugging Labels When debugging issues with labels, watch for this common pitfall: Specifying conflicting text wrapping and font adjustment settings. The lineBreakMode property describes how text should wrap or truncate within the label. If you set a value for this property that causes text to wrap to another line, do not set the adjustsFontSizeToFitWidth and adjustsLetterSpacingToFitWidth properties to YES, those fields ar used to scale the font size to fit into the label without adding line breaks. Elements Similar to a Label The following element provides similar functionality to a label: Text Field. Text fields allows the user to input a single line of text into an app. You typically use text fields to gather small amounts of text from the user and perform some immediate action, such as a search operation, based on that text. For more information, see “Text Fields” (page 165). Labels Internationalizing Labels 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 54
  • 55. Navigation bars allow you to present your app’s content in an organized and intuitive way. A navigation bar is displayed at the top of the screen, and contains buttons for navigating through a hierarchy of screens. A navigation bar generally has a back button, a title, and a right button. The most common way to use a navigation bar is with a navigation controller. You can also use a navigation bar as a standalone object in your app. Navigation bars allow the user to: ● Navigate to the previous view ● Transition to a new view Implementation: ● Navigation bars are implemented in the UINavigationBar class and discussed in the UINavigationBar Class Reference. ● Navigation items are implemented in the UINavigationItem class and discussed in the UINavigationItem Class Reference. ● Bar button items are implemented in the UIBarButtonItem class and discussed in the UIBarButtonItem Class Reference. ● Bar items are implemented in the UIBarItem class and discussed in the UIBarItem Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 55 Navigation Bars
  • 56. Configuring Navigation Bars Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Navigation Bar Content After you create a navigation bar, either in conjunction with a navigation controller or as a standalone object, you need to add content to the bar. A navigation bar can display a left button, title, prompt string, and right button. The navigation bar displays information from a stack of UINavigationItem objects. At any given time, the UINavigationItem that is currently the topItem of the stack determines the title and other optional information in the navigation bar, such as the right button and prompt. The UINavigationItem that is immediately below the topItem is the backItem, which determines the appearance of the left or back button. You can also add bar button items to a UINavigationItem. A UIBarButtonItem generally has a title and either a custom image or one of the system-supplied images listed in UIBarButtonSystemItem. It’s common to have a right bar button, but you can also use a left bar button in the place of a back button. Navigation Bars Configuring Navigation Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 56
  • 57. To add any of these elements to a navigation bar, select the desired item from the Object library in Interface Builder and drag it to your storyboard. Then, you customize the contents in the Attributes Inspector as described in “Setting Navigation Bar Images” (page 59). Formoreinformationabouttheelementsthatyouaddtoanavigationbar,seeUINavigationItemClassReference and UIBarButtonItem Class Reference. Specifying Navigation Bar Behavior The most common way to use a navigation bar is with a UINavigationController object. A navigation controller manages the navigation between different screens of content for you. It also creates the navigation bar automatically, and pushes and pops navigation items as appropriate. You can add a navigation controller to your app in Interface Builder or programmatically. To use Interface Builder to create a navigation controller, see “Creating a Navigation Interface Using a Storyboard” in View Controller Catalog for iOS. To create a navigation controller programmatically, see “Creating a Navigation Interface Programmatically” in View Controller Catalog for iOS. A navigation controller automatically assigns itself as the delegate of its navigation bar object. Attempting to change the delegate raises an exception. For more information about using a navigation bar with navigation controller, see “Navigation Controllers”. When you use a navigation bar as a standalone object, you set the initial appearance of the navigation bar by creating the appropriate UINavigationItem objects and adding them to the navigation bar object stack. When you create your standalone navigation bar in Interface Builder, Xcode creates the corresponding UINavigationItem objects for the elements you drag to the navigation bar. You are also responsible for managing the stack of UINavigationItem objects when you use a navigation bar as a standalone object. You push new navigation items onto the stack using the pushNavigationItem:animated: method and pop items off the stack using the popNavigationItemAnimated: method. In addition to pushing and popping items, you can also set the contents of the stack directly using either the items property or the setItems:animated: method. You might use these methods at launch time to restore your interface to its previous state or to push or pop more than one navigation item at a time. Assign a custom delegate object to the delegate property and use that object to intercept messages sent by the navigation bar. Delegate objects must conform to the UINavigationBarDelegate protocol. The delegate notifications let you track when navigation items are pushed or popped from the stack. You use these notifications to update the rest of your app’s user interface. For more information about implementing a delegate object, see UINavigationBarDelegate Protocol Reference. Navigation Bars Configuring Navigation Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 57
  • 58. Customizing Navigation Bar Appearance You can customize the appearance of a navigation bar by setting the properties depicted below. To customize the appearance of all navigation bars in your app, use the appearance proxy (for example, [UINavigationBar appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Specifying Navigation Bar Style Navigation bars have two standard appearance styles: translucent white with dark text (default) or translucent black with light text. Use the Style (barStyle) field to select one of these standard styles. Adjusting Navigation Bar Tint You can specify a custom tint color for the navigation bar background using the Tint (barTintColor) field. The default background tint color is white. Additionally, you can set a custom tint color for the interactive elements within a navigation bar—including button images and titles—programmatically using the tintColor property. The navigation bar will inherit its superview’s tint color if a custom one is set, or show the default system blue color if none is set. For more information, see “Adjusting View Tint Color” (page 19). Navigation Bars Configuring Navigation Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 58
  • 59. Setting Navigation Bar Images You can set a custom background image for your navigation bar. You can do this using setBackgroundImage:forBarMetrics:. Note that you must specify bar metrics because navigation bars have different dimensions on different devices and orientations. You can also use a custom shadow image for the navigation bar using the shadowImage property. To show a custom shadow image, you must also set a custom background image. Setting Navigation Bar Translucency Navigation bars are translucent by default in iOS 7. Additionally, there is a system blur applied to all navigation bars. This allows your content to show through underneath the bar. These settings automatically apply when you set any style for barStyle or any custom color for barTintColor. If you prefer, you can make the navigation bar opaque by setting the translucent property to NO programmatically. In this case, the bar draws an opaque background using black if the navigation bar has UIBarStyleBlack style, white if the navigation bar has UIBarStyleDefault, or the navigation bar’s barTintColor if a custom value is defined. If the navigation bar has a custom background image, the default translucency is automatically inferred from the average alpha values of the image. If the average alpha is less than 1.0, the navigation bar will be translucent by default; if the average alpha is 1.0, the search bar will be opaque by default. If you set the translucent property to YES on a navigation bar with an opaque custom background image, the navigation bar makes the image translucent. If you set the translucent property to NO on a navigation bar with a translucent custom background image, the navigation bar provides an opaque background for the image using black if the navigation bar has UIBarStyleBlack style, white if the navigation bar has UIBarStyleDefault, or the navigation bar’s barTintColor if a custom value is defined. Formatting Navigation Bar Title The titleTextAttributes property specifies the attributes for displaying the bar’s title text. You can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the text attribute keys described in NSString UIKit Additions Reference. You can adjust the vertical position of a navigation bar’s title using the setTitleVerticalPositionAdjustment:forBarMetrics: method. Note that you must specify bar metrics because navigation bars have different dimensions for different devices and screen orientations. Navigation Bars Configuring Navigation Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 59
  • 60. Setting Bar Button Item Glyphs Any bar button in a navigation bar can have a custom image instead of text. You can provide this image to your bar button item during initialization. Note that a bar button image will be automatically rendered as a template image within a navigation bar, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19). Using Auto Layout with Navigation Bars You can create Auto Layout constraints between a navigation bar and other user interface elements. You can create any type of constraint for a navigation bar besides a baseline constraint. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Navigation Bars Accessible Navigation bars are accessible by default. The default accessibility trait for a navigation bar is User Interaction Enabled. With VoiceOver enabled on an iOS device, after the user navigates to a new view in the hierarchy, VoiceOver reads the navigation bar’s title, followed by the name of the left bar button item. When the user taps on an element in a navigation bar, VoiceOver reads the name and the type of the element, such as, “General back button,” “Keyboard heading,” and “Edit button.” For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Navigation Bars For more information, see Internationalization Programming Topics. Debugging Navigation Bars When debugging issues with navigation bars, watch for this common pitfall: Navigation Bars Using Auto Layout with Navigation Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 60
  • 61. Specifying conflicting appearance settings. When customizing navigation bar appearance with a style or color, use one option or the other, but not both. Conflicting settings for navigation bar appearance will be resolved in favor of the most recently set value. For example, setting a new style clears any custom tint color you have set. Similarly, setting a custom tint color overrides any style you have set. Elements Similar to a Navigation Bar The following classes provide similar functionality to a navigation bar: ● Toolbar. A navigation controller can also manage a toolbar. On iPhone, this toolbar always appears at the bottom edge of the screen, but on iPad a toolbar can appear at the top of the screen. You can create a toolbar with a navigation controller, or as a standalone object. Unlike a navigation bar, which contains controls for navigating through a hierarchy of screens, a toolbar contains controls that perform actions related to the contents of the screen. For example, a toolbar might contain Share button and a Search button. For more information about toolbars, see “Toolbars” (page 104). ● Tab Bar. Similar to a navigation bar, a tab bar allows the user to switch between different views. However, a tab bar is persistent, which means that the user can select any tab from any other tab. By contrast, a navigation bar presents a linear path through various screens. For more information about tab bars, see “Tab Bars” (page 83). Navigation Bars Elements Similar to a Navigation Bar 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 61
  • 62. A picker view lets the user choose between certain options by spinning a wheel on the screen. Picker views are well suited for choosing things like dates and times (as the date picker does) that have a moderate number of discrete options. Other examples include picking which armor to wear in a game and picking a font for text in a word processor. The list of options should be ordered in some logical way to make scanning easier. Picker views allow the user to: ● Quickly choose between a set of distinct options Implementation: Date pickers are implemented in the UIDatePicker class and discussed in the UIDatePicker Class Reference. Configuring Picker Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Picker View Content Programmatically Populating a picker requires both a data source and a delegate. It is not possible to populate a picker in Interface Builder; you must do this programmatically. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 62 Picker Views
  • 63. Picker views need a delegate to display data and appropriately handle user interaction. The delegate adopts the UIPickerViewDelegate protocol and provides the content for each component’s row, either as an attributed string, a plain string, or a view, and it typically responds to new selections or deselections. It also implements methods to return the drawing rectangle for rows in each component—these optional methods are only needed if the delegate returns a view as part of the picker’s content. Additionally, picker views require a data source. The data source adopts the UIPickerViewDataSource protocol and implements the required methods to return the number of components (columns) and the number of rows in each component. Note that the actual contents of each row comes from the delegate, not the data source. For information about delegates and data sources, see “Delegates and Data Sources”. After setting the data source and delegate, set the initial selection by calling the selectRow:inComponent:animated: without animation. Typically this is done in a the viewDidLoad method of the view’s view controller. If the picker is visible, use animation when you update the selection. You can dynamically change the rows of a component by calling the reloadComponent: method, or dynamically change the rows of all components by calling the reloadAllComponents method. When you call either of these methods, the picker view asks the delegate for new component and row data, and asks the data source for new component and row counts. Reload a picker view when a selected value in one component should change the set of values in another component. For example, changing a row value from February to March in one component should change a related component representing the days of the month. Specifying Picker View Behavior You cannot customize the picker view’s selection indicator on iOS 7. The selection indicator is always shown, so toggling the Shows Selection Indicator (showsSelectionIndicator) box has no effect. Customizing Picker View Appearance You cannot customize the appearance of picker views. Using Auto Layout with Picker Views You can create an Auto Layout constraint between a picker view and other user interface elements. You can create any type of constraint for a picker view besides a baseline constraint. Picker Views Using Auto Layout with Picker Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 63
  • 64. Picker views usually reside at the bottom of the screen in all device orientations. Select Bottom Space to Superview and set the relation equal to 0 for the date picker to pin to the bottom of the screen in all device orientations. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Picker Views Accessible Picker views are accessible by default. The default accessibility trait for a picker view is Adjustable. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Picker Views To internationalize picker view, you must provide localized translations of each string in the picker. For more information, see Internationalization Programming Topics. Debugging Picker Views When debugging issues with picker views, watch for this common pitfall: Not testing localizations. Be sure to test the pickers in your app with the localizations you intend to ship. Elements Similar to a Picker View The following elements provide similar functionality to a picker view: ● Date Picker. Uses a picker to let the user pick a date and time. For more information, see “Date Pickers” (page 131). ● Stepper. Lets the user increment and decrement a value. For more information, see “Steppers” (page 156). Picker Views Making Picker Views Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 64
  • 65. A progress view is used to illustrate the progress of a task over time in an app. You use a progress view to let the user know how long until an operation completes, such as a download. The Mail app uses progress views in several different situations, including when it’s downloading new messages or sending an outgoing message. Progress views allow the user to: ● Receive feedback on a loading operation. ● See an estimate of how much time is left until a task finishes. Implementation: Progress views are implemented in the UIProgressView class and discussed in the UIProgressView Class Reference. Configuring Progress Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 65 Progress Views
  • 66. Setting Progress View Value You can set the initial progress as a float between 0 and 1 by using the Progress (progress) field in the Attributes Inspector. You can also do this programmatically using the setProgress:animated: method without animation. This is typically done in the viewDidLoad method of the view controller. If the progress view is visible, use animation when you update the progress. Customizing Progress View Appearance You can customize the appearance of a progress view by setting the properties depicted below. To customize the appearance of all progress views in your app, use the appearance proxy (for example, [UIProgressView appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Selecting Progress View Style Progress Views Configuring Progress Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 66
  • 67. With progress views, you have two style options: default and bar. You can specify either value by using the Style (progressViewStyle) field. There is no difference in functionality, only in appearance. The Default style has blue-tinted progress and a gray track; the Bar style is a thinner version of the default. Adjusting Progress View Tint You can adjust the tint of two parts of the progress view: the track and the progress. The track tint applies to the area of the track that is not filled, while the progress tint applies to the portion of the progress bar that is filled. Use the Track Tint (trackTintColor) and Progress Tint (progressTintColor) fields to set custom colors for the track and progress. You can adjust the tint for either style of the progress view. Using Auto Layout with Progress Views You can create Auto Layout constraints between a progress view and other user interface elements. You can create any type of constraint for a progress view besides a baseline constraint. To keep a progress view centered and adjust its width according to device orientation or screen size, you can use Auto Layout to pin it to its superview. Using the Auto Layout Pin menu, create Leading Space to Superview and Trailing Space to Superview constraints and set their values equal to each other. Doing this ensures that the endpoints of your progress view are a specified distance from the edges of its superview. With these constraints, the progress view stays centered and its width adjusts automatically for different device orientations and screen sizes. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Progress Views Using Auto Layout with Progress Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 67
  • 68. Making Progress Views Accessible Progress views are accessible by default. The default accessibility traits for a progress view are Updates Frequently and User Interaction Enabled. The Updates Frequently accessibility trait means that the progress view doesn't send update notifications when its state changes. This trait tells an assistive app that it should poll for changes in the progress view when necessary. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Progress Views Progress views have no special properties related to internationalization. However, if you use a progress view with a label, make sure you provide localized strings for the label. For more information, see Internationalization Programming Topics. Elements Similar to a Progress View The following element provides similar functionality to a progress view: Activity Indicator View. For an indeterminate progress indicator—or, informally, a “spinner”—use an activity indicator view. For more information, see “Activity Indicators” (page 26). Progress Views Making Progress Views Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 68
  • 69. A scroll view allows users to see content that is larger than the scroll view’s boundaries. When a scroll view first appears—or when users interact with it—vertical or horizontal scroll indicators flash briefly to show users that there is more content they can reveal. Other than the transient scroll indicators, a scroll view has no predefined appearance. Scroll views allow the user to: ● View content that does not fit on the screen of the device Implementation: Scroll views are implemented in the UIScrollView class and discussed in the UIScrollView Class Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 69 Scroll Views
  • 70. Configuring Scroll Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Scroll View Content You set scroll view content programmatically by adding subviews to its content view with the addSubview: method. Specifying Scroll View Behavior Scroll views need a delegate to handle scrolling, dragging, and zooming. By assigning a view controller as the scroll view’s delegate and implementing any or all of the UIScrollViewDelegate methods, you can define these behaviors. Scroll Views Configuring Scroll Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 70
  • 71. A scroll view responds to the speed and direction of gestures to reveal content in a way that feels natural to people. When users drag content in a scroll view, the content follows the touch; when users flick content, the scroll view reveals the content quickly and stops scrolling when the user touches the screen or when the end of the content is reached. A scroll view can also operate in paging mode, in which each drag or flick gesture reveals one app-defined page of content. Use the Shows Horizontal Scrollers (showsHorizontalScrollIndicator) and Shows Vertical Scrollers (showsVerticalScrollIndicator) boxes to specify whether the corresponding scroll indicator should be visible during tracking and fades out after tracking. These options are enabled by default; toggle off is you do not want the scroller to be shown. You can specify whether scrolling is enabled or disabled in the scroll view using the Scrolling Enabled (scrollEnabled) checkbox. Scrolling is enabled by default. When scrolling is disabled, the scroll view does not accept touch events; it forwards them up the responder chain. If you check the Paging Enabled (pagingEnabled) box, the the scroll view stops on multiples of the scroll view’s bounds when the user scrolls, giving the effect of scrolling through a single page at a time. If you turn on directional lock by checking the Direction Lock Enabled (directionalLockEnabled) box, a user will only be able to scroll in one direction at a time. By default, a user can scroll in both directions, or diagonally. If the Bounces Zoom (bouncesZoom) option is enabled, when zooming exceeds either the maximum or minimum limits for scaling, the scroll view temporarily animates the content scaling just past these limits before returning to them. If this option is disabled, zooming stops immediately at one a scaling limits. Using the Delays Content Touches (delaysContentTouches) checkbox, you can specify whether the scroll view delays the handling of touch-down gestures. When enabled, the view delays handling the touch-down gesture until it can determine if scrolling is the intent. Scroll Views Configuring Scroll Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 71
  • 72. You can indicate whether touches in the content view always lead to tracking by using the Cancellable Content Touches (canCancelContentTouches) checkbox. When enabled, if a user drags their finger enough to initiate a scroll within a view in the content that has begun tracking a finger touching it, that view receives a touchesCancelled:withEvent: message and the scroll view handles the touch as a scroll. When disabled, the scroll view does not scroll regardless of finger movement once the content view starts tracking. Use the Bounces (bounces) checkbox to indicate whether the scroll view bounces past the edge of content and back again. Enable Bounce Horizontally (alwaysBounceHorizontal) if you want content to bounce when scrolled horizontally, and Bounce Vertically (alwaysBounceVertical) if you want content to bounce when scrolled vertically. You can use the Min Zoom (minimumZoomScale) and Max Zoom (maximumZoomScale) fields to specify how much the scroll view’s content can be zoomed. The maximum zoom scale must be greater than the minimum zoom scale for zooming to be enabled. The default value is 1.0. Scroll Views Configuring Scroll Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 72
  • 73. Customizing Scroll View Appearance You can customize the appearance of a scroll view by setting the properties depicted below. To customize the appearance of all scroll views in your app, use the appearance proxy (for example, [UIScrollView appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Setting Scroll View Style The only way to customize the appearance of a scroll view is by setting the style of the scroll indicators. There are three different choices for indicator style: default (black with a white border), white, or black. You can set the indicator style using the “Style” (indicatorStyle) field in the Attributes Inspector. Specifying Scroll View Content Layout Scroll views have a number of options that dictate how their content is laid out. You specify the size of the content using the contentSize property, which is initially set to zero. You can use the contentInset property to specify a content inset, which is the distance that the content is padded or inset from the enclosing scroll view. Additionally, you can use the contentOffset property or the setContentOffset:animated: method to set the point at which the origin of the content view is offset from the origin of the scroll view. Scroll Views Configuring Scroll Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 73
  • 74. Using Auto Layout with Scroll Views You can create Auto Layout constraints between a scroll view and other user interface elements. You can create any type of constraint for a scroll view besides a baseline constraint. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Scroll Views Accessible Scroll views are accessible by default. The default accessibility trait for a scroll view is "User Interaction Enabled.” For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Scroll Views For more information, see Internationalization Programming Topics. Elements Similar to a Scroll View The following elements provide similar functionality to a scroll view: ● Table View. A scrolling view that displays data items in a single-column list. For more information, see “Table Views” (page 88). ● Collection View. A scrollable view that displays an ordered collection of data items using standard or custom layouts. Similar to a table view, a collection view gets data from your custom data source objects and displays it using a combination of cell, layout, and supplementary views. For more information, see “Collection Views” (page 35). Scroll Views Using Auto Layout with Scroll Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 74
  • 75. A search bar provides an interface for text-based searches with a text box and buttons such as search and cancel. A search bar accepts text from users, which can be used as input for a search (shown here with placeholder text). A scope bar, which is available only in conjunction with a search bar—allows users to define the scope of a search (shown here below a search bar). Search bars allow the user to: ● Quickly find a value in a large collection ● Create a scope filter Implementation: Search bars are implemented in the UISearchBar class and discussed in the UISearchBar Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 75 Search Bars
  • 76. Configuring Search Bars Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Search Bars Configuring Search Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 76
  • 77. Setting Search Bar Content The Text (text) field contains the current search text; you can use it to set an initial search. Don’t use it to provide a description of the search; use placeholder text instead. Placeholder text is specified in the Placeholder (placeholder) field, and is visible only when there is no other text in the search field. Placeholder text is styled differently to communicate its different meaning to the user and it is automatically cleared when the user starts typing. It is suitable for very short descriptions of what the user should enter in the search field. The prompt text is specified in the Prompt (prompt) field. It appears directly above the search bar. Unlike the placeholder text, the prompt text is visible whether or not the user has entered text in the search field, so it is suitable for longer descriptions or directions. Search bars can display a number of different buttons. The Cancel button is intended to terminate a search operation; you can display this button by selecting the Shows Cancel Button checkbox. The Search Results and Bookmarks buttons appear in the right side of search bar, and can be toggled to display those respective views. You can display one of these buttons by selecting either the Shows Search Results Button (showsSearchResultsButton) or Shows Bookmarks Button (showsBookmarkButton) checkbox. Note that you cannot display both of these buttons simultaneously; if both properties are enabled, only the Search Results button is visible. Note: These buttons are merely user interface elements and have no functionality. You must implement the appropriate functionality yourself using the corresponding UISearchBarDelegate methods. Search Bars Configuring Search Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 77
  • 78. A search bar can also display a scope bar, which lets users limit the scope of a search. For example, when searching in an email app, the user could restrict the search to the Inbox or to a particular folder. To display a scope bar, check the Shows Scope Bar (showsScopeBar) box and add an array of scope bar titles as strings to the Scope Titles (scopeButtonTitles) field. Specifying Search Bar Behavior Search bars need a delegate to handle user interaction. You implement the UISearchBarDelegate protocol on a delegate object to respond to user actions—for example, performing the search. Every search bar needs a delegate object that implements the UISearchBarDelegate protocol. The delegate is responsible for taking actions in response to user input such as editing the search text, starting or canceling a search, and tapping in the scope bar. At the very minimum, the delegate needs to perform a search after text is entered in the text field. A user types content into a search bar using a keyboard, which has a number of customization options: ● Keyboard layout. The Keyboard field allows you to select from a number of different keyboard layouts. Match the keyboard layout to the purpose and scope of the search bar. The default keyboard layout is an alphanumeric keyboard in the device’s default language. For a list of possible keyboard types, see UIKeyboardType. ● Capitalization scheme. The Capitalization field specifies how text should be capitalized in the search bar: no capitalization, every word, every sentence, or every character. The no capitalization scheme is selected by default. ● Auto-correction. The Correction field simply disables or enables auto-correct in the search bar. Search Bars Configuring Search Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 78
  • 79. Customizing Search Bar Appearance You can customize the appearance of a search bar by setting the following properties: To customize the appearance of all search bars in your app, the appearance proxy (for example, [UISearchBar appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Specifying Search Bar Style Bars have two standard appearance styles: translucent white with dark text (default) or translucent black with light text. Use the Style (barStyle) field to select one of these standard styles. Adjusting Search Bar Tint You can specify a custom tint color for the search bar background using the Tint (barTintColor) field. The default background tint color is white. Additionally, you can set a custom tint color for the interactive elements within a search bar—including the scope bar, cancel button, and cursor—programmatically using the tintColor property. The search bar will inherit its superview’s tint color if a custom one is set, or show the default system blue color if none is set. For more information, see “Adjusting View Tint Color” (page 19). Search Bars Configuring Search Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 79
  • 80. Specifying Search Bar Background Images A search bar can have a background image that covers the area behind the search field. Use the backgroundImage property to set a background image for your search bar. You can also set the background image for a search bar’s scope bar using the scopeBarBackgroundImage property. Single-pixel images or stretchable images are stretched; otherwise, the image is tiled. If you set one of these background image properties, you should also set the other to give your app interface a consistent look. Setting Search Bar Translucency Search bars are translucent by default on iOS 7. Additionally, there is a system blur applied to all search bars. This allows your content to show through underneath the bar. These settings automatically apply when you set any style for barStyle or any custom color for barTintColor. If you prefer, you can make the search bar opaque by setting the translucent property to NO programmatically. In this case, the bar draws an opaque background using black if the search bar has UIBarStyleBlack style, white if the search bar has UIBarStyleDefault, or the search bar’s barTintColor if a custom value is defined. If the search bar has a custom background image, the default translucency is automatically inferred from the average alpha values of the image. If the average alpha is less than 1.0, the search bar will be translucent by default; if the average alpha is 1.0, the search bar will be opaque by default. If you set the translucent property to YES on a search bar with an opaque custom background image, the search bar makes the image translucent. If you set the translucent property to NO on a search bar with a translucent custom background image, the search bar provides an opaque background for the image using black if the search bar has UIBarStyleBlack style, white if the search bar has UIBarStyleDefault, or the search bar’s barTintColor if a custom value is defined. Specifying Search Bar Layout You can also control certain aspects of the search bar’s layout by providing position adjustments: for icons using the positionAdjustmentForSearchBarIcon: method, for the background image using the searchFieldBackgroundPositionAdjustment property, and for search text using the searchTextPositionAdjustment property. Using Auto Layout with Search Bars You can create Auto Layout constraints between a search bar and other user interface elements. You can create any type of constraint for a search bar besides a baseline constraint. Search Bars Using Auto Layout with Search Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 80
  • 81. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Search Bars Accessible Search bars are accessible by default. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Search Bars To internationalize a search bar, you must provide localized strings for the following properties: ● placeholder ● prompt ● text ● scopeButtonTitles For more information, see Internationalization Programming Topics. Debugging Navigation Bars When debugging issues with navigation bars, watch for these common pitfalls: ● Specifying conflicting appearance settings. When customizing search bar appearance with a style or color, use one option or the other, but not both. Conflicting settings for search bar appearance will be resolved in favor of the most recently set value. For example, setting a new style clears any custom tint color you have set. Similarly, setting a custom tint color overrides any style you have set. ● Performance issues. If search operations can be carried out very rapidly, it is possible to update the search results as the user is typing by implementing the searchBar:textDidChange: method on the delegate object. However, if a search operation takes more time, you should wait until the user taps the Search button before beginning the search in the searchBarSearchButtonClicked: method. Always perform search operations a background thread to avoid blocking the main thread. This keeps your app responsive to the user while the search is running and provides a better user experience. Search Bars Making Search Bars Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 81
  • 82. Elements Similar to a Search Bar The following element provides similar functionality to a search bar: Toolbar. A toolbar object contains controls that allow the user to perform actions related to objects onscreen. For more information, see “Toolbars” (page 104). Search Bars Elements Similar to a Search Bar 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 82
  • 83. A tab bar provides easy access to different views in an app. Use a tab bar to organize information in your app by subtask. The most common way to use a tab bar is with a tab bar controller. You can also use a tab bar as a standalone object in your app. Tab bars allow the user to: ● Quickly navigate within an app ● Get an understanding of the app’s layout Implementation: ● Tab bars are implemented in the UITabBar class and discussed in the UITabBar Class Reference. ● Tab bar items are implemented in the UITabBarItem class and discussed in the UITabBarItem Class Reference. Configuring Tab Bars Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 83 Tab Bars
  • 84. Specifying Tab Bar Content Each tab on a tab bar is represented as a UITabBarItem, and you use the UITabBarItem class methods to create a tab bar item. Each tab bar item has a title, selected image, unselected image, and a badge value. After you create your tab bar items, add them to your tab bar with the items property, which is an array of UITabBarItem objects. If you want to animate changes to your tab bar items array, use the setItems:animated: method instead. Specifying Tab Bar Behavior You can change the contents of a tab bar at runtime, and allow users to add, remove, or reorder tabs. To present a modal view that allows users to customize a tab bar, use the beginCustomizingItems: method. You can also add a UITabBarDelegate object to your app. The tab bar delegate receives messages when the user customizes the tab bar. The most common way to use a tab bar is in conjunction with a tab bar controller. A UITabBarController object manages the various tab views and view controllers, and the tab bar itself. If you use a tab bar controller, you should not use the UITabBar methods or properties to modify the tab bar. If you do, the system throws an exception. For more information about how to create a tab bar interface with an associated tab bar controller, see “Tab Bar Controllers”. Customizing Tab Bar Appearance You can customize the appearance of a tab bar by setting the properties depicted below. To customize the appearance of all tab bars in your app, use the appearance proxy (for example, [UITabBar appearance]). For more information, see “Using Appearance Proxies” (page 18). Specifying Tab Bar Style Tab bars have two standard appearance styles: translucent white with dark text (default) or translucent black with light text. Use the barStyle property to programmatically select one of these standard styles. Tab Bars Configuring Tab Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 84
  • 85. Adjusting Tab Bar Tint You can specify a custom tint color for the bar background using the Tint (barTintColor) field. The default background tint color is white. Use the Image Tint (selectedImageTintColor) field to specify the bar item’s tint color when that tab is selected. By default, that color is blue. Setting Tab Bar Images The selection indicator image is shown when a tab is selected. It is drawn on top of the tab bar, behind the bar item icon. By default, there is no selection indicator image, but you can set a custom one using the selectionIndicatorImage property. By default, there is no divider image between tabs on a tab bar. You can set custom divider images for each combination of left and right tab control states using the setDividerImage:forLeftState:rightState: method. If you use custom dividers, make sure to set divider images all combinations of tabs states: left selected, right selected, or both unselected. You can also set a custom background image for your entire tab bar using the backgroundImage property. If you set this property with a stretchable image, the image is stretched. If you use a non-stretchable image, the image is tiled. If you want to use custom shadow image for the tab bar, set the shadowImage property. To show a custom shadow image, you must also set a custom background image with backgroundImage. Setting Tab Bar Translucency Tab bars are translucent by default on iOS 7. Additionally, there is a system blur applied to all tab bars. This allows your content to show through underneath the bar. These settings automatically apply when you set any style for barStyle or any custom color for barTintColor. If you prefer, you can make the tab bar opaque by setting the translucent property to NO programmatically. In this case, the bar draws an opaque background using black if the tab bar has UIBarStyleBlack style, white if the tab bar has UIBarStyleDefault, or the tab bar’s barTintColor if a custom value is defined. If the tab bar has a custom background image, the default translucency is automatically inferred from the average alpha values of the image. If the average alpha is less than 1.0, the tab bar will be translucent by default; if the average alpha is 1.0, the tab bar will be opaque by default. If you set the translucent property to YES on a tab bar with an opaque custom background image, the tab bar makes the image translucent. If Tab Bars Configuring Tab Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 85
  • 86. you set the translucent property to NO on a tab bar with a translucent custom background image, the tab bar provides an opaque background for the image using black if the tab bar has UIBarStyleBlack style, white if the tab bar has UIBarStyleDefault, or the tab bar’s barTintColor if a custom value is defined. Setting Tab Bar Item Glyphs Each item in a tab bar can have a custom selected image and unselected image. You can specify these images when you initialize a tab bar item using the initWithTitle:image:selectedImage: method. Note that a tab bar item image will be automatically rendered as a template image within a tab bar, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19). Using Auto Layout with Tab Bars You can create Auto Layout constraints between a tab bar and other user interface elements. You can create any type of constraint for a tab bar besides a baseline constraint. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Tab Bars Accessible Tab bars are accessible by default. With VoiceOver enabled on an iOS device, when a user touches a tab in a tab bar, VoiceOver reads the title of the tab, its position in the bar, and whether it is selected. For example in the iTunes app on iPad, you might hear “Selected, Audiobooks, four of seven” or “Genius, six of seven.” For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Tab Bars To internationalize a tab bar, you must provide localized strings for the tab bar item titles. For more information, see Internationalization Programming Topics. Tab Bars Using Auto Layout with Tab Bars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 86
  • 87. Elements Similar to a Tab Bar The following classes provide similar functionality to a tab bar: ● Segmented Control. Similar to a tab bar, a segmented control functions as a button that shows different views. If you want to provide functionality similar to a tab bar, but don’t want those controls to be persistent, consider using a segmented control. Remember that a tab bar should be accessible from every location in an app. For more information, see “Segmented Controls” (page 142). ● Navigation Bar. A navigation bar also allows users to navigate through different content views, but it offers a linear path. With a tab bar, a user can view any other tab at any given time. For more information, see “Navigation Bars” (page 55). ● Toolbar. Both a tab bar and a toolbar are always visible onscreen. However, unlike a tab bar, which switches between views, a UIToolbar object contains controls that allow the user to perform actions related to objects onscreen. For more information, see “Toolbars” (page 104). Tab Bars Elements Similar to a Tab Bar 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 87
  • 88. A table view presents data in a scrollable list of multiple rows that may be divided into sections. It presents data in a single-column list of multiple rows and is a means for displaying and editing hierarchical lists of information. For instance, the Mail application uses a table view to display email messages in a user’s inbox. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 88 Table Views
  • 89. In normal mode, selecting a message allows the user to read it. In editing mode, selecting a message allows the user to delete it from the inbox. Table views provide a simple yet versatile interface for managing and interacting with collections of data. Table views allow the user to: Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 89
  • 90. ● Navigate through hierarchically structured data ● View an indexed list of items ● See detail information and controls in visually distinct groupings ● Interact with a selectable list of options Implementation: ● Table views are implemented in the UITableView class and discussed in UITableView Class Reference. ● Individual table cells are implemented in the UITableViewCell class and discussed in UITableViewCell Class Reference. ● Table headers and footers are implemented in the UITableViewHeaderFooterView class and discussed in UITableViewHeaderFooterView Class Reference. Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 90
  • 91. Configuring Table Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Table Views Configuring Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 91
  • 92. Setting Table Content To display content, a table view must have a data source. The data source mediates between the app’s data model and the table view. A table view’s data source must conform to the UITableViewDataSource protocol. For more information about the data source, see “Data Source and Delegate” in Table View Programming Guide for iOS. Each individual table cell can display a variety of content. Cells that use the default basic style can display an image and text label, and cells that use one of the other three standard styles can display an image, text label, and detail text label in a particular pre-defined layout. You can set a cell’s image programmatically using the “Image” (image) field in the Attributes Inspector, which appears when the cell is in one of the four standard styles. However, you must set the textLabel and detailTextLabel properties programmatically. To learn more about table cell content, see “A Closer Look at Table View Cells”. A cell’s content—image, text, and any custom views—resides in its content view. If you want to customize your table cell beyond the standard cell styles, you can set the cell style to custom and add your custom views to the cell’s contentView property programmatically. Each table—and each section within that table—can have a header and a footer that displays text or custom content. You use headers and footers to display additional information about the table or its sections. The UITableViewHeaderFooterView class implements a reusable view that you can place at the top or bottom of a table or table section. Headers and footers can either display a text label and optional detail text label, or custom content. You can set the textLabel and detailTextLabel properties programmatically. Alternatively, you can add your custom views to the header or footer’s contentView property programmatically. If you are using any custom content in a header or footer, do not use the standard textLabel and detailTextLabel properties; instead, add your own labels to the content view. For more information about headers and footers, see “Grouped Table Views” in Table View Programming Guide for iOS and UITableViewHeaderFooterView Class Reference. Table Views Configuring Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 92
  • 93. Specifying Table View Behavior Table views need a delegate to manages the appearance and behavior. By assigning a view controller as the table view’s delegate and implementing any or all of the UITableViewDelegate methods, you can allow the delegate to manage selections, configure section headings and footers, help to delete and reorder cells, and perform other actions. Table selection style controls the number of cells a user can select at a given time. There are three types of selection available for individual cells in a table view: single, multiple, or none. Tables can have different types of selection in normal mode and editing mode. For example, you can allow users to select multiple items in normal mode, but only delete one item at a time in editing mode. In Interface Builder, you can specify selection style for normal mode using the Selection field, and for editing mode using the Editing field. You can also choose whether a cell is visually highlighted upon selection by checking the Show Selection on Touch box. Index Row Limit (sectionIndexMinimumDisplayRowCount) allows you to specify the minimum number of rows required in the table for the index to be shown. Note that this applies to plain style tables only. A reuse identifier is a string used to identify a cell that can be reused for multiple rows of a table view (for performance purposes). You can set this property using the Identifier (reuseIdentifier) field in the Attributes Inspector. You can also set a reuse identifier programmatically during cell initialization. You can set indentation values for cell content through the Level (indentationLevel) and Width (indentationWidth) fields. The width is the value for each level of indentation. You can indicate whether to indent cell content in editing mode by checking the Indent While Editing (shouldIndentWhileEditing) box. Table Views Configuring Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 93
  • 94. Checking the Shows Re-order Controls (showsReorderControl) box will cause the cell to display a control that allows it to be reordered within the table in editing mode. However, you must also implement the UITableViewDataSource method tableView:moveRowAtIndexPath:toIndexPath: and set tableView:canMoveRowAtIndexPath: to return YES to get the reordering control to appear in a particular cell. This part must be done programmatically. To make the table view aware of a header or footer view, you need to register it. You do this using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method. Similar to that of a table cell, the header or footer’s reuse identifier is a string used to identify a header or footer view that can be reused for multiple headers or footers within a table. It is set during initialization using the initWithReuseIdentifier: method. Table Views Configuring Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 94
  • 95. Customizing Table View Appearance You can customize the appearance of a table view by setting the properties depicted below. To customize the appearance of all table views in your app, use the appearance proxy (for example, [UITableView appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Specifying Table View Style Table Views Configuring Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 95
  • 96. Separator style dictates how a table’s cells are separated visually. You can customize the style and color of table cell separators using the Separator (separatorStyle, separatorColor) fields in the Attributes Inspector. There are three available styles: single line, etched line, or none. Table style affects the appearance of a table’s sections. Tables have two styles: plain and grouped. Certain appearance properties only apply when a table view is displayed in one particular style. You can select the style of a table to be plain or grouped using the Style (style) attribute. Setting Cell Selection Style Cell selection style specifies which color the outline of a selected cell will appear: gray, blue, or none. Use the Selection (selectionStyle) field to set cell selection style. Choosing Accessory Types You can also set accessory types for normal and editing modes through the Accessory (accessoryType) and Editing Acc. (editingAccessoryType) fields in the Attributes Inspector. For a list of standard accessory types, see Cell Accessory Type. Alternatively, you can use custom views by setting the accessoryView and editingAccessoryView properties programmatically. Custom views have precedence over the standard accessory types, so if you set the accessory view properties, your cell ignores the value of the accessoryType and editingAccessoryType properties. Specifying Cell Layout The cell style attribute determines how content is visually laid out in a cell. You can select one of four existing styles—or create a custom one—in the Style field of a table cell’s Attributes Inspector. Table Views Configuring Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 96
  • 97. Specifying Header and Footer Appearance You can customize the appearance of your header or footer by setting a custom background view or tint color. The background view is placed behind the contentView and used to display static background content behind the header or footer. For example, you might assign an image view to this property and use it to display a custom background image. Alternatively, you can set a custom tint for the header or footer view by setting its tintColor property. Avoid setting both a custom background view and a custom tint. Using Auto Layout with Table Views You can create Auto Layout constraints between a table view and other user interface elements. You can create any type of constraint for a table view besides a baseline constraint. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Table Views Accessible Table views are accessible by default. Accessibility for tables is handled at the table cell level. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Table Views To internationalize a table view, you must provide localized strings for text labels and detail text labels of all table cells, headers, and footers. For more information, see Internationalization Programming Topics. Elements Similar to a Table View The following element provides similar functionality to a table view: Scroll View. A class that provides support for displaying content that is larger than the size of the app’s window. Use this class when your app contains too much information to display on an iOS device screen at one time. For more information, see “Scroll Views” (page 69). Table Views Using Auto Layout with Table Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 97
  • 98. A text view accepts and displays multiple lines of text. Text views support scrolling and text editing. You typically use a text view to display a large amount of text, such as the body of an email message. Text views allow the user to: ● Input user content into an app Implementation: Text views are implemented in the UITextView class and discussed in the UITextView Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 98 Text Views
  • 99. Configuring Text Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Text View Content Set text view content using the Text (text and attributedText) field. Both properties get set whether you specified the value of the field to be plain or attributed. Plain text supports a single set of formatting attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports multiple sets of attributes that apply to individual characters or ranges of characters in the string. Text Views Configuring Text Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 99
  • 100. Specifying Text View Behavior By default, users can add, remove, or change text within a text view. To disable these behaviors, uncheck the Editable (editable) checkbox in the Attributes Inspector. A text view is capable of recognizing when text is formatted as a link, address, phone number, or event. If you enable the corresponding Detection (dataDetectorTypes) checkboxes, users will be able to trigger the appropriate action for each type of text by clicking it in the text view. For example, they will be able to call a phone number or add an event to their calendar. A user types content into a text view using a keyboard, which has a number of customization options: ● Keyboard layout. The Keyboard field allows you to select from a number of different keyboard layouts. Match the keyboard layout to the purpose of the text view. If the user will be entering a web address, select the URL keyboard. The default keyboard layout is an alphanumeric keyboard in the device’s default language. For a list of possible keyboard types, see UIKeyboardType. You cannot customize the appearance of the keyboard on iOS 7. ● Return key. The return key, which appears in the bottom right of the keyboard, allows the user to notify the system when they are finished editing the text field. You can select one of several standard return key types by using the Return Key field. The return key is disabled by default, and only becomes enabled when a user types something into the text view. If you want your user to be able to press the return key any Text Views Configuring Text Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 100
  • 101. time the keyboard is open, even if the input is empty or incomplete, you can select the Auto-enable Return Key checkbox. Different return keys are intended to provide the user with an understanding of what action hitting the key will trigger. Note that simply selecting a different return key appearance does not provide you with the functionality intended by that key; you must implement the action yourself. Unlike text field delegates, a text view delegate does not provide a method that gets called when the return key is pressed. However, you can implement custom return key functionality in the text view delegate’s textView:shouldChangeTextInRange:replacementText: method, which gets called after every keystroke. ● Capitalization scheme. The Capitalization field specifies how text should be capitalized in the text view: no capitalization, every word, every sentence, or every character. The sentence capitalization scheme is selected by default. ● Auto-correction. The Correction field simply disables or enables auto-correct in the text view. ● Secure content. The Secure checkbox is unselected by default. Selecting it causes the text view to obscure text once it is typed, allowing the user to safely enter secure content—such as a password—into the view. You can use the text view delegate methods to handle custom keyboard dismissal. Customizing Text View Appearance You can customize the appearance of a text view by setting the properties depicted below. To customize the appearance of all text views in your app, use the appearance proxy (for example, [UITextView appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Specifying Text Appearance Text views can have one of two types of text: plain or attributed. Plain text supports a single set of formatting attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports multiple sets of attributes that apply to individual characters or ranges of characters in the string. Text Views Configuring Text Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 101
  • 102. Using Auto Layout with Text Views You can create Auto Layout constraints between a text view and other user interface elements. You can create any type of constraint for a text view besides a baseline constraint. You generally want the text view to fill the full width of your screen. To ensure that this happens correctly on all devices and orientations, you can create “Leading Space to Superview” and “Trailing Space to Superview” constraints, and set both values equal to 0. This will ensure that the text view remains pinned to the edges of the device screen. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Text Views Accessible Text views are accessible by default. The default accessibility trait for a text view is User Interaction Enabled. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Text Views For more information, see Internationalization Programming Topics. Debugging Text Views When debugging issues with text views, watch for this common pitfall: Text Views Using Auto Layout with Text Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 102
  • 103. Placing a text view inside of a scroll view. Text views handle their own scrolling. You should not embed text view objects in scroll views. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. Elements Similar to a Text View The following element provides similar functionality to a text view: Scroll View. Use a scroll view for scrollable content. For more information, see “Scroll Views” (page 69). Text Views Elements Similar to a Text View 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 103
  • 104. A toolbar usually appears at the bottom of a screen, and displays one or more buttons called toolbar items. Generally, these buttons provide some sort of tool that is relevant to the screen’s current content. A toolbar is often used in conjunction with a navigation controller, which manages both the navigation bar and the toolbar. Toolbars allow the user to: ● Select one of a set of performable actions within a given view Implementation: ● Toolbars are implemented in the UIToolbar class and discussed in UIToolbar Class Reference. ● Bar button items are implemented in the UIBarButtonItem class and discussed in UIBarButtonItem Class Reference. ● Bar items are implemented in the UIBarItem class and discussed in UIBarItem Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 104 Toolbars
  • 105. Configuring Toolbars Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Toolbar Content After you create a toolbar, you need to add items to the bar. Each item is a UIBarButtonItem object, which you can add to the toolbar directly in Interface Builder or in code using the items property. If you want to animate changes to your toolbar items array, use the setItems:animated: method. Toolbars Configuring Toolbars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 105
  • 106. You can specify the content of a particular bar button item by selecting its identifier. The identifier can either be custom or take on the value of well-know system buttons such as Edit or Done. For a list of system identifiers, see UIBarButtonSystemItem. If you are using a bar button item with the custom identifier, you can set some of its properties at the UIBarItem level. For example, you can specify either a custom title or image using the Title (title) or Image (image) fields. You can assign a tag to your bar button item using the Tag (tag) field. This is intended to be a unique identifier for your button so you can access it in code. Specifying Toolbar Behavior Toolbars do not need a delegate to function properly; their parent view controller can define their behavior without implementing any delegate protocols. When a user clicks a particular button on the toolbar, you can respond by performing some corresponding action in your app, such as deleting an email. You register the target-action method for a bar button item as shown below. self.myBarButtonItem.target = self; self.myBarButtonItem.action = @selector(myAction:); Alternatively, you can Control-drag the bar button item’s selector from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). Toolbars Configuring Toolbars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 106
  • 107. You can disable or enable a given button on the toolbar by selecting the button in Interface Builder and toggling its Enabled (enabled) box. A common way to create and manage a toolbar is in conjunction with a navigation controller. The navigation controller displays the toolbar and populates it with items from the currently visible view controller. Using a navigation controller is ideal for an app design where you want to change the contents of the toolbar dynamically. However, you should not use a navigation controller if your app does not have or need a navigation bar. For more information, see “Displaying a Navigation Toolbar” in View Controller Catalog for iOS. Customizing Toolbar Appearance You can customize the appearance of a toolbar by setting the properties depicted below. To customize the appearance of all toolbars in your app, use the appearance proxy (for example, [UIToolbar appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Toolbars Configuring Toolbars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 107
  • 108. Specifying Toolbar Style Toolbar have two standard appearance styles: translucent white with dark text (default) or translucent black with light text. Use the Style (barStyle) field to select one of these standard styles. Adjusting Toolbar Tint You can specify a custom tint color for the bar background using the Tint (barTintColor) field. The default background tint color is white. Additionally, you can set a custom tint color for the interactive elements within a toolbar bar—including the button images and text—programmatically using the tintColor property. The toolbar bar will inherit its superview’s tint color if a custom one is set, or show the default system blue color if none is set. For more information, see “Adjusting View Tint Color” (page 19). Setting Toolbar Background Images You can set a custom background image for your toolbar using the backgroundImageForToolbarPosition:barMetrics: method. The image must be the correct dimensions in order to cover the area of the toolbar correctly. Remember to set custom images for different sets of bar metrics. If you want to use custom shadow image for the toolbar, use the setShadowImage:forToolbarPosition: method. To show a custom shadow image, you must also set a custom background image with backgroundImageForToolbarPosition:barMetrics:. Setting Toolbar Translucency Toolbars are translucent by default on iOS 7. Additionally, there is a system blur applied to all toolbars. This allows your content to show through underneath the bar. Toolbars Configuring Toolbars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 108
  • 109. These settings automatically apply when you set any style for barStyle or any custom color for barTintColor. If you prefer, you can make the toolbar opaque by setting the translucent property to NO programmatically. In this case, the bar draws an opaque background using black if the toolbar has UIBarStyleBlack style, white if the toolbar has UIBarStyleDefault, or the toolbar’s barTintColor if a custom value is defined. If the toolbar has a custom background image, the default translucency is automatically inferred from the average alpha values of the image. If the average alpha is less than 1.0, the toolbar will be translucent by default; if the average alpha is 1.0, the toolbar will be opaque by default. If you set the translucent property to YES on a toolbar with an opaque custom background image, the toolbar makes the image translucent. If you set the translucent property to NO on a toolbar with a translucent custom background image, the toolbar provides an opaque background for the image using black if the toolbar has UIBarStyleBlack style, white if the toolbar has UIBarStyleDefault, or the toolbar’s barTintColor if a custom value is defined. Setting Bar Button Item Glyphs Any bar button in a toolbar can have a custom image instead of text. You can provide this image to your bar button item during initialization. Note that a bar button image will be automatically rendered as a template image within a toolbar, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19). Using Auto Layout with Toolbars You can create Auto Layout constraints between a toolbar and other user interface elements. You can create any type of constraint for a toolbar besides a baseline constraint. You cannot create Auto Layout constraints for individual bar button items. However, you can use bar button items with the Fixed Space and Flexible Space identifiers to determine the spacing of buttons on your toolbar. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Toolbars Accessible Toolbars are accessible by default. For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Toolbars Using Auto Layout with Toolbars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 109
  • 110. Internationalizing Toolbars To internationalize a toolbar, you must provide localized strings for all button titles. Remember to test all localizations, as button size may change unexpectedly when using localized strings. For more information, see Internationalization Programming Topics. Debugging Toolbars When debugging issues with toolbars, watch for this common pitfall: Trying to customize the content of a non-custom bar button item. If you try to set a custom title or image—at the UIBarItem level—for a bar button item with a non-custom identifier, the bar button item’s identifier will automatically switch to the custom type in Interface Builder. Elements Similar to a Toolbar The following elements provide similar functionality to a toolbar: ● Tab Bar. A toolbar is most similar to a tab bar—both can appear at the bottom of the screen. Use a toolbar to display controls that perform specific functions, and use a tab bar to allow the user to switch between different views or subtasks. For more information, see “Tab Bars” (page 83). ● Navigation Bar. For more information, see “Navigation Bars” (page 55). Toolbars Internationalizing Toolbars 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 110
  • 111. A web view is a region that can display rich HTML content (shown here between the navigation bar and toolbar in Mail on iPhone). Web views allow the user to: ● View web content within an app Implementation: Web views are implemented in the UIWebView class and discussed in the UIWebView Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 111 Web Views
  • 112. Configuring Web Views Generally, the easiest way to configure views—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Web View Content Programmatically To get your web view to display content, you simply create a UIWebView object, attach it to a window, and send it a request to load web content. Use the loadRequest: method to begin loading web content, the stopLoading method to stop loading, and the loading property to find out if a web view is in the process of loading. You can create the web view object in code or in Interface Builder, but you can load content in code only. [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]]]; Specifying Web View Behavior You can set your web view to automatically scale web content to fit on the screen of the user’s device. By default, this behavior is disabled, but you can enable it by checking the Scales Page To Fit (scalesPageToFit) box in Attributes Inspector. Enabling this property also allows the user to zoom in and out in the web view. Web Views Configuring Web Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 112
  • 113. A web view is capable of recognizing when web text is formatted as a link, address, phone number, or event. If you enable the corresponding Detection (dataDetectorTypes) checkboxes, users will be able to trigger the appropriate action for each type of text by clicking it in the web view. For example, they will be able to call a phone number or add an event to their calendar. Customizing Web View Appearance You cannot customize the appearance of a web view. Using Auto Layout with Web Views You can create Auto Layout constraints between a web view and other user interface elements. You can create any type of constraint for a web view besides a baseline constraint. You generally want the web view to fill the full width of your screen. To ensure that this happens correctly on all devices and orientations, you can create “Leading Space to Superview” and “Trailing Space to Superview” constraints, and set both values equal to 0. This will ensure that the web view remains pinned to the edges of the device screen. For general information about using Auto Layout with iOS views, see “Using Auto Layout with Views” (page 20). Making Web Views Accessible Web views are accessible by default. The default accessibility trait for a web view is "User Interaction Enabled.” For general information about making iOS views accessible, see “Making Views Accessible” (page 21). Internationalizing Web Views Web views have no special properties related to internationalization. For more information, see Internationalization Programming Topics. Debugging Web Views When debugging issues with web views, watch for these common pitfalls: Web Views Using Auto Layout with Web Views 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 113
  • 114. ● Placing a web view inside of a scroll view. Web views handle their own scrolling. You should not embed web view objects in scroll views. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. ● Not testing web content size. Web content comes in a variety of sizes, and it may be difficult to view content that is too large or too small for a device screen. Enable the scalesPageToFit property to allow users to zoom in or out if you anticipate that this might be the case for your app. ● Not having a valid Internet connection. Since web views rely entirely on the Internet, a working connection is essential to loading web view content. Slow or disabled connections may make it appear as if your web view is not functioning properly when the actual problem is with the connection. Elements Similar to a Web View The following element provides similar functionality to a web view: Scroll View. Use a scroll view for scrollable content. For more information, see “Scroll Views” (page 69). Web Views Elements Similar to a Web View 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 114
  • 115. ● “About Controls” (page 116) ● “Buttons” (page 123) ● “Date Pickers” (page 131) ● “Page Controls” (page 137) ● “Segmented Controls” (page 142) ● “Text Fields” (page 165) ● “Sliders” (page 149) ● “Steppers” (page 156) ● “Switches” (page 161) 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 115 Controls
  • 116. Important: This is a preliminary document for an API or technology in development. Although this document has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only by registered members of the applicable Apple Developer program. Apple is supplying this confidential information to help you plan for the adoption of the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be tested with final operating system software and final documentation. Newer versions of this document may be provided with future seeds of the API or technology. A control is a communication tool between a user and an app. The user interacts with a control to convey a particular action or intention to the app. Controls can be used to manipulate content, provide user input, navigate within an app, or execute other pre-defined actions. Controls are simple, straightforward, and familiar to users because the appear throughout many iOS apps. The UIControl class is the base class for all controls on iOS, and defines the functionality that is common to all controls. You should never use it directly; instead, use one of its subclasses. Each subclass of UIControl defines appearance, behavior, and intended usage specific to that particular control. By using controls carefully and consistently in your app, you can convey to users what they have the freedom and ability to do within the app. Controls allow the user to: ● Interact with an app. ● Manipulate or edit app content. ● Convey user intent to the app in a straightforward way. Implementation: Controls are implemented in the UIControl class and discussed in UIControl Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 116 About Controls
  • 117. Configuring Controls Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. Each field in the Attributes Inspector that corresponds to a particular API property lists it in parentheses. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Control Content Each subclass of UIControl has different content or values that you can set. To learn about setting content for a particular control, read its corresponding chapter: ● Buttons ● Date Pickers ● Page Controls ● Segmented Controls ● Text Fields ● Sliders ● Steppers ● Switches Specifying Control Behavior Understanding Control States A control state describes the current interactive state of a control: normal, selected, enabled, or highlighted. A control can have more than one state at a time, and you can change a control’s state at any point. For a full listing of control states, see UIControlState. About Controls Configuring Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 117
  • 118. When a user interacts with a control, the control’s state changes appropriately. You can configure controls to have different appearances for different states to provide users with feedback about which state the control is in. For example, you might configure a button to display one image when it is in its normal state and a different image when it is highlighted. The fastest way to configure the initial state of a control is by using the Attributes Inspector: When a control is enabled, a user can interact with it. When a control is disabled, it appears grayed out and does not respond to user interaction. Controls are enabled by default; to disable a control, uncheck the “Enabled” (enabled) box in the Attributes Inspector. A control enters a temporary highlighted state when when a touch enters and exits during tracking and when there is a touch up event. A highlighted state is temporary. You can customize the highlighted appearance of some controls, such as buttons. Controls are not highlighted by default; to set a control’s initial state to highlighted, check the “Highlighted” (highlighted) box in the Attributes Inspector. When a user taps on a control, the control enters the selected state. For many controls, this state has no effect on behavior or appearance. However, some subclasses may have different appearance depending on their selected state. For example, UISegmentedControl segments have a distinctly different appearance when selected. You can set a control to be selected using the “Selected” (selected) checkbox. Understanding Control Events A control event represents various physical gestures that users can make on controls, such as lifting a finger from a control, dragging a finger into a control, and touching down within a text field. For a full listing of control events, see UIControlEvents. Understanding the Target-Action Mechanism The target-action mechanism is a model for configuring a control to send an action message to a target object after a specific control event. For example, when a user interacts with a slider, it generates a UIControlEventValueChanged control event. You could use this event to update a label’s text to the current value of the slider. In this case, the sender is the slider, the control event is Value Changed, the action is updating the label’s text, and the target is the controller file containing the label as an IBOutlet. To create a relationship between the slider, the control event, the target, and the action, you can do one of two things: 1. Call the addTarget:action:forControlEvents: method within your target file: About Controls Configuring Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 118
  • 119. [self.mySlider addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; 2. Use the Connections Inspector in Interface Builder to Control-drag the slider’s Value Changed event to the action method in the target file. 3. Control-click the slider in Interface Builder, and drag its Value Changed event to the target object in your Storyboard. Select the appropriate action from the list of actions available for the target. For more information, see “Target-Action in UIKit” in Cocoa Fundamentals Guide Customizing Control Appearance Adjusting Control Content Alignment Certain controls—such as buttons and text fields—can contain custom images or text. For these controls, you can specify the alignment of that content by using the “Horizontal Alignment” (contentHorizontalAlignment) and “Vertical Alignment” (contentVerticalAlignment) options in Attributes Inspector. Using the horizontal alignment options, you can specify whether the content appears aligned with the left, center, or right of the control, or whether it fills the width of the control. Using the vertical alignment options, you can specify whether the content appears aligned with the top, center, or bottom of the control, or whether it fills the height of the control. This is a great tool for ensuring your content appears exactly where you want it to within your control (for example, centering text in a text field). About Controls Configuring Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 119
  • 120. Note: These alignment options apply to the content of a control, not the control itself. For information about aligning controls with respect to other controls or views, see “Using Auto Layout with Controls” (page 120). Using Auto Layout with Controls The auto layout system allows you to define layout constraints for user interface elements, such as views and controls. Constraints represent relationships between user interface elements. You can create auto layout constraints by selecting the appropriate element or group of elements and selecting an option from the menu in the bottom right corner of Xcode’s Interface Builder. Auto layout contains two menus of constraints: pin and align. The Pin menu allows you to specify constraints that define some relationship based on a particular value or range of values. Some apply to the control itself (width) while others define relationships between elements (horizontal spacing). The following tables describes what each group of constraints in the auto layout menu accomplishes: PurposeConstraint Name Sets the width or height of a single element. Sets the horizontal or vertical spacing between exactly two elements. Sets the spacing from one or more elements to the leading, trailing, top, or bottom of their container view. Leading and trailing are the same as left and right in English, but the UI flips when localized in a right-to-left environment. Sets the widths or heights of two or more elements equal to each other. Aligns the left, right, top, or bottom edges of two or more elements. Aligns two or more elements according to their horizontal centers, vertical centers, or bottom baselines. Note that baselines are different from bottom edges. These values may not be defined for certain elements. Aligns the horizontal or vertical centers of one or more elements with the horizontal or vertical center of their container view. About Controls Using Auto Layout with Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 120
  • 121. The “Constant” value specified for any Pin constraints (besides Widths/Heights Equally) can be part of a “Relation.” That is, you can specify whether you want the value of that constraint to be equal to, less than or equal to, or greater than or equal to the value. For more information, see Cocoa Auto Layout Guide. Making Controls Accessible Controls are accessible by default. To be useful, an accessible user interface element must provide accurate and helpful information about its screen position, name, behavior, value, and type. This is the information VoiceOver speaks to users. Visually impaired users can rely on VoiceOver to help them use their devices. The iOS SDK contains a programming interface and tools that help you ensure that the user interface elements in your application are both accessible and useful. The UI Accessibility programming interface defines the following attributes: ● Label. A short, localized word or phrase that succinctly describes the control or view, but does not identify the element’s type. Examples are “Add” or “Play.” ● Traits. A combination of one or more individual traits, each of which describes a single aspect of an element’s state, behavior, or usage. For example, an element that behaves like a keyboard key and that is currently selected can be characterized by the combination of the Keyboard Key and Selected traits. ● Hint. A brief, localized phrase that describes the results of an action on an element. Examples are “Adds a title” or “Opens the shopping list.” ● Frame. The frame of the element in screen coordinates, which is given by the CGRect structure that specifies an element’s screen location and size. ● Value. The current value of an element, when the value is not represented by the label. For example, the label for a slider might be “Speed,” but its current value might be “50%.” About Controls Making Controls Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 121
  • 122. Controls automatically provide value, frame, and default trait information. You can set a label, hint, and adjust the list of traits using the Identity Inspector in Interface Builder. For more information, see Accessibility Programming Guide for iOS. About Controls Making Controls Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 122
  • 123. Buttons let a user initiate behavior with a tap. You communicate a button’s function through a textual label or with an image. Your app changes button appearance based upon user touch interactions, using highlighting, changes in the label or image, color, and state to indicate the button action dynamically. Buttons allow the user to: ● Initiate behavior with a tap ● Initiate an action in the app with a single simple gesture Implementation: Buttons are implemented in the UIButton class and discussed in the UIButton Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 123 Buttons
  • 124. Configuring Buttons Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Buttons Configuring Buttons 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 124
  • 125. Setting Button Content You can set a button’s content using the Type (buttonType) field in the Attributes Inspector. In iOS 7, the rounded rect button type has been deprecated in favor of the system button, UIButtonTypeSystem. Button objects can be specified as one of five standard types—system, detail disclosure, info light, info dark, and add contact. The detail disclosure, info, and add contact button types are supplied with standard image graphics to indicate their purpose to the user. These images cannot be customized. There is also a custom type for great versatility in defining a unique interface. Specifying Button Behavior Buttons do not need a delegate to function properly; a view controller can define their behavior and functionality without implementing any delegate protocols. A button sends the UIControlEventTouchUpInside event when the user taps it. You can respond to this event by performing some corresponding action in your app, such as saving information. You register the target-action methods for a button as shown below. [self.myButton addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; Alternatively, you can Control-drag the button’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). If the Shows Touch On Highlight (showsTouchWhenHighlighted) box is enabled, when a user presses on the button, there will be a white glow where the touch event occurred on the button. Buttons Configuring Buttons 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 125
  • 126. If your button has a custom image, the Highlighted Adjusts Image (adjustsImageWhenHighlighted) and Disabled Adjusts Image (adjustsImageWhenDisabled) options allow you to specify whether highlighted or disabled states affect the appearance of the image. For example, with those options enabled, the image might get darker when the button is highlighted, and dimmer when the button is disabled. If your button content extends past the bounds of the button, you can specify which part of the content to truncate using the Line Break (lineBreakMode) field. Customizing Button Appearance You can customize the appearance of a button by setting the properties depicted below. To customize the appearance of all buttons in your app, use the appearance proxy (for example, [UIButton appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Setting the Button State A button has four states to configure for appearance—default, highlighted, selected, and disabled. To configure the button’s appearance for each state, first select the state from the State Config menu in the Attributes Inspector and then use the other menus and text boxes in the Attributes Inspector’s appearance property group. Buttons Configuring Buttons 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 126
  • 127. Setting Button Shadow Shadow offset defines how far the shadow is drawn from the button text. You can customize the offset for both dimensions using the Shadow Offset (titleShadowOffset) fields. You can select the Reverses On Highlight (reversesTitleShadowWhenHighlighted) checkbox if you want your shadow offset to automatically flip directions when the button is in the UIControlStateHighlighted state. Note: These shadow properties only have an effect on buttons with plain—not attributed—text. Adjusting Button Tint You can specify a custom button tint using the tintColor property. This property sets the color of the button image and text. If you do not explicitly set a tint color, the button will inherit its superview’s tint color. For more information, see “Adjusting View Tint Color” (page 19). Buttons Configuring Buttons 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 127
  • 128. Formatting Button Title Button can have one of two types of text: plain or attributed. Plain text supports a single set of formatting attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports multiple sets of attributes that apply to individual characters or ranges of characters in the string. The default title is “Button”, intended to be altered to the app need. The title string set in the default state is used in all other states unless you enter a replacement title string for a specific state. Available title customization options differ depending on whether you are using plain or attributed text: Setting Button Images Using the Image (currentImage) field, you can specify an image to appear within the content of your button. If the button has a title, this image appears to the left of it, and centered otherwise. The image does not stretch or condense, so make sure to select an image that is the proper size to appear in your button. Note that this image will be automatically rendered as a template image within the button, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19). The Background (currentBackgroundImage) field allows you to specify an image to appear behind button content and fill the entire frame of the button. The image you specify will stretch to fill the button if it is too small. It will be cropped if it is too large. Buttons Configuring Buttons 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 128
  • 129. The images set in the default state are used in all other states unless you enter a replacement image for a specific state. Adjusting Edge Insets The part of your button that makes up your image and text is your content. You can offset this content by using edge insets. In the Edge field, select whether you want to offset just your title, just your image, or both together. Depending on your selection, the changes you make to the Inset fields will adjust the titleEdgeInsets, imageEdgeInsets, and contentEdgeInsets properties, respectively. There should be no reason for you to adjust the edge insets for info, contact, or disclosure buttons. This functionality is intended for custom or rounded rectangle buttons only. Using Auto Layout with Buttons You can create Auto Layout constraints between a button and other user interface elements. You can create any type of constraint for a button. For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Making Buttons Accessible Buttons are accessible by default. The default accessibility traits for a button are Button and User Interaction Enabled. Buttons Using Auto Layout with Buttons 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 129
  • 130. The accessibility label, traits, and hint are spoken back to the user when VoiceOver is enabled on a device. The button’s title overwrites its accessibility label; even if you set a custom value for the label, VoiceOver speaks the value of the title. VoiceOver speaks this information when a user taps the button once. For example, when a user taps the Options button in Camera, VoiceOver speaks the following: "Options. Button. Shows additional camera options." For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Internationalizing Buttons To internationalize a button, you much provide localized strings for its title text. For more information, see Internationalization Programming Topics. Debugging Buttons When debugging issues with buttons, watch for these common pitfalls: ● Setting images that are the wrong dimensions. A button does not scale or stretch its content images, but it does does not scale or stretch any custom images that you add to it. For example, if you specify an on image that is smaller than the switch, you will see the switch’s on tint color in the space that’s not covered by the image. On the other hand, if you specify an on image that is too big, it can bleed over into the space intended for the off image. The size of on/off images should be 77 points wide and 27 points tall. ● A common button development problem is when a button is tapped and nothing responds, or the app crashes, when all the code seems well formed and in place. This is commonly caused by an error in linking the button to its action message, often the result of having changed the action message name or the layout of buttons during user interface or code development. Elements Similar to a Button The following element provides similar functionality to a button: Bar Button. An icon used to execute an action from a toolbar or for navigation in a navigation bar. For more information, see “Toolbars” (page 104). Buttons Internationalizing Buttons 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 130
  • 131. A date picker is a control used for selecting a specific date, time, or both. It also provides an interface for a countdown timer, although it does not implement the functionality. Date pickers provide a straightforward interface for managing date and time selection, allowing users to specify a particular date quickly and efficiently. Date pickers allow the user to: ● Specify a particular date and/or time ● Use a countdown timer interface Implementation: Date pickers are implemented in the UIDatePicker class and discussed in the UIDatePicker Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 131 Date Pickers
  • 132. Configuring Date Pickers Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Setting Date Picker Values A date picker’s currently selected time displays at the center of the picker. This value defaults to the time the picker object was created, but you can adjust this value using the Date (date) field in Attributes Inspector. Use the Minimum Date (minimumDate) and Maximum Date (maximumDate) fields to constrain the date picker’s Date Pickers Configuring Date Pickers 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 132
  • 133. range. For example, if you are asking the user to input a birthday, you might set the maximum date to the current year. Creating a date scope that aligns with your picker’s intended functionality simplifies the user’s task of finding and setting the correct date. When a date picker is in the countdown mode, you can use the Timer (countDownDuration) field to specify the seconds from which the countdown timer should count down. This value is ignored if the date picker is not in UIDatePickerModeCountDownTimer mode. Note that even though the timer shows a countdown in seconds, a user can only specify minute intervals to count down from. Note: A date picker object presents the countdown timer but does not implement it; the application must set up an NSTimer object and update the seconds as they’re counted down. Specifying Date Picker Behavior Date pickers do not need a delegate to function properly; their parent view controller can define their behavior without implementing any delegate protocols. A date picker sends the UIControlEventValueChanged event when the user finishes rotating one of the wheels to change the date or time. You can respond to this event by performing some corresponding action in your app, such as updating the time for a calendar event. You register the target-action methods for a date picker as shown below. Date Pickers Configuring Date Pickers 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 133
  • 134. [self.myDatePicker addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; Alternatively, you can Control-drag the date picker’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). The most important setting in determining a date picker’s functionality is its mode. A date picker’s mode determines what content it displays to the user, as well as how it behaves. There are four mode settings: date and time, date only, time only, or countdown timer. The date and/or time modes allow users to select a specific point in time. The countdown timer allows users to specify a relative time period until an event occurs. You can specify one of these options using the Mode (datePickerMode) field in Attributes Inspector. You can choose a specific locale for your date picker to appear in by adjusting the “Locale” (locale) field. For more information, see “Internationalizing Date Pickers” (page 135). You can also specify the interval at which the date picker displays minutes. A smaller interval gives users more precise control over selecting a date picker time. Choose an interval in the Interval (minuteInterval) field. Customizing Date Picker Appearance You cannot customize the appearance of date pickers. Using Auto Layout with Date Pickers You can create Auto Layout constraints between a date picker and other user interface elements. You can create any type of constraint for a date picker besides a baseline constraint. Date Pickers Using Auto Layout with Date Pickers 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 134
  • 135. Date pickers usually reside at the bottom of the screen in all device orientations. Select “Bottom Space to Superview” and set the relation equal to 0 for the date picker to pin to the bottom of the screen in all device orientations. For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Making Date Pickers Accessible Date pickers are accessible by default. Each rotating wheel in the date picker is its own accessibility element and has the “Adjustable” (UIAccessibilityTraitAdjustable) trait. The accessibility value, traits, and hint for each picker wheel are spoken back to the user when VoiceOver is enabled on a device. VoiceOver speaks this information when a user taps on a picker wheel. For example, when a user taps the hours column on the Add Alarm page (Clock > Alarm > Add), VoiceOver speaks the following: "2 o'clock. Picker item. Adjustable. Swipe up or down with one finger to adjust the value." For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Internationalizing Date Pickers Date pickers handle their own internationalization; the only thing you need to do it specify the appropriate locale. You can choose a specific locale for your date picker to appear in by setting the “Locale” (locale) field in Attributes Inspector. This changes the language that the date picker is presented in, but also the format of the date and time (for example, certain locales present days before month names, or prefer a 24-hour clock over a 12-hour clock). The width of the date picker automatically accommodates for the length of the localization. To use the system language, leave this property to default. For more information, see Internationalization Programming Topics. Debugging Date Pickers When debugging issues with date pickers, watch for these common pitfalls: Date Pickers Making Date Pickers Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 135
  • 136. ● Specifying conflicting date bounds. Check the bounds of your minimumDate and maximumDate. If the maximum date is less than the minimum date, both properties are ignored. The minimum and maximum dates are also ignored in the countdown-timer mode (UIDatePickerModeCountDownTimer). ● Selecting an incorrect interval. Check that the minuteInterval can be evenly divided into 60; otherwise, the default value is used (1). Elements Similar to a Date Picker The following element provides similar functionality to a date picker: Picker View. A class like the date picker that can be used for selecting things other than date and time. For more information, see “Picker Views” (page 62). Date Pickers Elements Similar to a Date Picker 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 136
  • 137. A page control displays a horizontal series of dots, each of which represents a page or screen in an app. Although a page control doesn’t manage the display of content pages, you can write code that lets users navigate between pages by tapping the control. You can see examples of page controls in Weather—when you set more than one location—and in the summary, chart, and news view in Stocks (in portrait orientation). Typically, a page control is used with another view—such as a scroll view—that manages the pages and handles scrolling, panning, and zooming of the content. In this scenario, the scroll view usually uses paging mode to display the content, which is divided into separate views or into separate areas of one view. Page controls allow the user to: ● Have a visual indication of which page is currently displayed ● Navigate between pages in an app Implementation: Page controls are implemented in the UIPageControl class and discussed in the UIPageControl Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 137 Page Controls
  • 138. Configuring Page Controls Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. Specifying Page Control Values To specify the number of dots the page control should display, you can use the the # of Pages (numberOfPages) field in the Attributes Inspector. Note that when you create a page control in Interface Builder, the default number of dots is 3; when you create a page control programmatically, the default number of dots is 0. Use the Current (currentPage) field to specify the currently selected page. Note that page index begins at 0 instead of 1, so the maximum index of the currently selected page is one less than the total number of pages. Specifying Page Control Behavior Page controls need a delegate to handle user interaction. A page control doesn't automatically stay synchronized with the currently open page—or let users tap the control to transition between pages—unless you enable these actions in your app. To ensure that a page control's current-page dot corresponds to the page that is currently open in the scroll view, implement the UIScrollViewDelegate protocol in your view controller. Then, update the page control in the scrollViewDidScroll: delegate method and set the page control's currentPage property to the current page. Page Controls Configuring Page Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 138
  • 139. A page control sends the UIControlEventValueChanged event when the user taps it. You can respond to this event by performing some corresponding action in your app, such as transitioning to a different page in the scroll view. You register the target-action methods for a page control as shown below. [self.myPageControl addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; Alternatively, you can Control-drag the page control’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). By default, a page control displays one dot when an app contains only one page. To set the page control to display no dots when there is only one page, select the Hides for Single Page (hidesForSinglePage) checkbox in the Attributes Inspector. You can also choose to delay updating the page control’s display when the current page changes. If the Defers Page Display (defersCurrentPageDisplay) box is enabled, when the user clicks the control to go to a new page, the class defers updating the page control until it calls updateCurrentPageDisplay. This behavior is off by default, which means the page indicator updates immediately. Customizing Page Control Appearance You can customize the appearance of a page control by setting the properties depicted below. To customize the appearance of all page controls in your app, use the appearance proxy (for example, [UIPageControl appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Page Controls Configuring Page Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 139
  • 140. Adjusting Page Control Tint The only way to customize the appearance of a page control is by setting custom tints for the dots representing each page. The Current Page (currentPageIndicatorTintColor) field affects the color of the dot representing the currently displayed page, and the Tint Color (pageIndicatorTintColor) field affects the color of the dots representing every other page. The default color is white for the current page dot, and translucent gray for the other page dots. If you want your custom colors to be translucent, you must specify a color with an alpha value of less than 1.0. This must be done programmatically, as in the following example: self.myPageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.5]; self.myPageControl.pageIndicatorTintColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5]; Using Auto Layout with Page Controls You can create auto layout constraints between a page control and other user interface elements. You can create any type of constraint for a page control besides a baseline constraint. To keep a page control centered onscreen, you can use auto layout to pin a page control to its superview or align it with other elements. Typically, you leave space for a page control at the bottom of the screen, below the view that displays the pages. For general information about using auto layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Making Page Controls Accessible Page controls are accessible by default. The default accessibility traits for a page control are Updates Frequently and User Interaction Enabled. The Updates Frequently accessibility trait means that the page control doesn't send update notifications when its state changes. This trait tells an assistive app that it should poll for changes in the page control when necessary. Page Controls Using Auto Layout with Page Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 140
  • 141. When the user interacts with a page control, VoiceOver speaks "page x of y" where x is the current page and y is the total number of pages. For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Internationalizing Text Fields Page controls have no special properties related to internationalization. For more information, see Internationalization Programming Topics. Debugging Page Controls When debugging issues with page controls, watch for this common pitfall: Selecting an out of range current page. If you try to set a page control’s current page to be higher than the index of the last page, it will be set equal to the index of the last page. If you try to set a page control’s current page to be lower than 0, it will be set to 0. Elements Similar to a Page Control The following elements provide similar functionality to a page control: ● Scroll View. A class that supports a page-by-page scrolling experience in addition to panning and zooming of content. For more information, see “Scroll Views” (page 69). ● Page View Controller. A class that displays multiple content views in a book-like format and enables animated transitions between pages. For more information, see UIPageViewController Class Reference. Page Controls Internationalizing Text Fields 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 141
  • 142. A segmented control is a horizontal control made of multiple segments, each segment functioning as a discrete button. Segmented controls allow the user to: ● Interact with a compact group of a number of controls Implementation: Segmented controls are implemented in the UISegmentedControl class and discussed in the UISegmentedControl Class Reference. Configuring Segmented Controls Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. As you will read, a few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 142 Segmented Controls
  • 143. Setting Segmented Control Values Segmented controls are made up of a number of individual buttons called segments. You can choose the number of segments by setting the Segments (numberOfSegments) field. By default, a segmented control is created with two segments. Content for each segment is set individually. Using the Segment field, you can select a particular segment to modify its content. A segment may either have a text title or an image, but not both. Use the Title (titleForSegmentAtIndex:) or Image (imageForSegmentAtIndex:) fields to set one of these content properties. As stated in the HI guidelines, avoid creating a segmented control with some segments that contain text and others that images; just choose one or the other. Specifying Segmented Control Behavior Segmented controls do not need a delegate to function properly; their parent view controller can define their behavior without implementing any delegate protocols. A segmented control sends the UIControlEventValueChanged event when the user presses one of the segments. You can respond to this event by performing some corresponding action in your app, such as switching to a different layout. You register the target-action methods for a segmented control as shown below. [self.mySegmentedControl addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; Segmented Controls Configuring Segmented Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 143
  • 144. Alternatively, you can Control-drag the segmented control’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). If you set a segmented control to have a momentary selection style, its segments do not stay in a selected state when pressed. Instead, they are momentarily highlighted and then restored back to the normal control state. If you would like to enable this behavior, select the Momentary (momentary) checkbox in the Attributes Inspector. Note that setting the momentary selection behavior affects every segment in a segmented control; you cannot have a control with some momentary segments and some regular segments. You can specify whether a given segment is enabled or disabled. A user cannot interact with a segment that is disabled. Use the Enabled (isEnabledForSegmentAtIndex:) checkbox to specify whether a given segment is enabled for user interaction. Additionally, you can specify whether a particular segment is currently selected using the Selected (selectedSegmentIndex) checkbox. Note that only one segment can be selected at a time; if you set the selection for a given segment, the previously selected segment will become unselected. Segmented Controls Configuring Segmented Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 144
  • 145. Customizing Segmented Control Appearance You can customize the appearance of a segmented control by setting the properties depicted below. To customize the appearance of all segmented controls in your app, use the appearance proxy (for example, [UISegmentedControl appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Adjusting Segmented Control Tint You can specify a custom segmented control tint using the Tint (tintColor) field. This property sets the color of the segment images, text, dividers, borders, and selected segment. A translucent version of this color is also used to tint a segment when it is pressed and transitioning to being selected, as shown on the first segment below. If you do not explicitly set a tint color, the segmented control will inherit its superview’s tint color. For more information, see “Adjusting View Tint Color” (page 19). Segmented Controls Configuring Segmented Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 145
  • 146. Specifying Segmented Control Style You cannot customize the segmented control’s style on iOS 7. Segmented controls only have one style, and the Style (segmentedControlStyle) field has been deprecated. Specifying Segment Content Offset If you want the content of a particular segment to be offset from its default position, you can alter it using the Content Offset fields in Attributes Inspector. Setting Segmented Control Images If you need to customize the appearance of your segmented control beyond standard tinting, you might consider doing so using custom images. Since segmented controls have different metrics for portrait and landscape device orientations, remember to specify an appropriate image for each set of metrics. You can set a background image for each control state of your segmented control using the backgroundImageForState:barMetrics: method. You should also specify divider images for each combination of left and right segment states to give selected or highlighted segments a different look than segments in a normal state, as shown here: [mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:barMetrics]; [mySegmentedControl setDividerImage:image2 forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:barMetrics]; [mySegmentedControl setDividerImage:image3 forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:barMetrics]; Formatting Segment Titles The titleTextAttributesForState: property specifies the attributes for displaying the segment’s title text. You can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the text attribute keys described in NSString UIKit Additions Reference. Segmented Controls Configuring Segmented Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 146
  • 147. Setting Segment Glyphs You can use an image instead of title text for your segments. Note that a segment image will be automatically rendered as a template image within a segmented control, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19). Using Auto Layout with Segmented Controls You can create auto layout constraints between a segmented control and other user interface elements. You can create any type of constraint for a segmented control. For general information about using auto layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Making Segmented Controls Accessible The following listing demonstrates how you can set the accessibility label of programmatically-generated segments. NSString *title = @"∫"; title.accessibilityLabel = @"Integral"; [segmentedControl insertedSegmentedWithTitle:title]; UIImage *image = [UIImage imageNamed:@"GearImage.png"]; image.accessibilityLabel = @"Settings"; [segmentedControl insertedSegmentWithImage:image]; For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Internationalizing Segmented Controls To internationalize a segmented control, you must provide localized strings for all segment titles. Remember to test all localizations, as segment size may change unexpectedly when using localized strings. For more information, see Internationalization Programming Topics. Debugging Segmented Controls When debugging issues with segmented controls, watch for these common pitfalls: Segmented Controls Debugging Segmented Controls 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 147
  • 148. ● Specifying conflicting appearance settings. When customizing segment content with text or images, use one or the other, but not both. A segment cannot have both text and an image as its content. Whichever content property was set last will override the other one. ● Not setting custom images for every control state. If you use custom background and divider images for your segmented control, remember to set an image for every possible UIControlState combination. Any control state that does not have a corresponding custom image assigned to it will display the standard image instead. If you set one custom image, make sure to set them all. Elements Similar to a Segmented Control The following elements provide similar functionality to a segmented control: ● Tab Bar. A class used for navigating between views in an app. You should use a tab bar instead of a segmented control when you want to let the user move back and forth between distinct pages in your app. For more information, see “Tab Bars” (page 83). ● Toolbar. A class that allows users to perform certain actions in the current context. For more information, see “Toolbars” (page 104). Segmented Controls Elements Similar to a Segmented Control 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 148
  • 149. Sliders enable users to interactively modify some adjustable value in an app, such as speaker volume or screen brightness. For example, in GarageBand, sliders allow users to mix different settings for various effects. Users control a slider by moving its current value indicator along a continuous range of values between a specified minimum and maximum. Sliders allow the user to: ● Make smooth and continuous adjustments to a value ● Have relative control over a value within a range ● Set a value with a single simple gesture Implementation: Sliders are implemented in the UISlider class and discussed in the UISlider Class Reference. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 149 Sliders
  • 150. Configuring Sliders Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. You can customize the appearance of all sliders in your app using the appearance proxy (for example, [UISlider appearance]), or just of a single control. For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Setting Slider Values You can configure a minimum, maximum, and current value for your slider. By default, a slider’s minimum is set to 0, its maximum is set to 1, and its current value is set to 0.5. You can change these values by adjusting the Minimum (minimumValue), Maximum (maximumValue), and Current (value) fields in the Attributes Inspector. Sliders Configuring Sliders 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 150
  • 151. Specifying Slider Behavior Sliders do not need a delegate to function properly; their parent view controller can define their behavior without implementing any delegate protocols. A slider sends the UIControlEventValueChanged event when the user interacts it. You can respond to this event by performing some corresponding action in your app, such as adjusting music volume. You register the target-action methods for a slider as shown below. [self.mySlider addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; Alternatively, you can Control-drag the slider’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). You can specify when a slider’s UIControlEventValueChanged events are sent by toggling the Continuous (continuous) checkbox in the Attributes Inspector. In continuous delivery, the slider sends multiple value changed events as the user moves the thumb. In noncontinuous delivery, the slider sends one value changed event when the user releases the thumb. Continuous control event delivery is enabled by default. Customizing Slider Appearance You can customize the appearance of a slider by setting the properties depicted below. To customize the appearance of all sliders in your app, use the appearance proxy (for example, [UISlider appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Sliders Configuring Sliders 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 151
  • 152. Setting Minimum and Maximum Value Images The most common way to customize the slider’s appearance is to provide custom minimum and maximum value images. You can set a slider’s minimum and maximum value images in Interface Builder by selecting custom images in the Min Image (minimumValueImage) and Max Image (maximumValueImage) fields in the Attributes Inspector. These images sit at either end of the slider control and indicate which value that end of the slider represents. For example, a slider used to control volume might display a speaker with no sound waves emanating from it for the minimum value and display a speaker with many sound waves emanating from it for the maximum value, as illustrated here. Adjusting Slider Tint You can also set custom tints for each part of a slider. The minimum track image contains a blue highlight by default, while the maximum track and thumb images contain a white highlight. You can assign different tints for all of the standard parts provided by the slider. This can be done in the Attributes Inspector by setting the Min Track Tint (minimumTrackTintColor), Max Track Tint (maximumTrackTintColor), and Thumb Tint (thumbTintColor) fields. Note that you can only adjust the tint of the default track and thumb images, not custom images. Setting the tint of a part of the slider that has custom images associated with it will remove those images. Setting Track and Thumb Images Programmatically Slider controls draw the track using two customizable images. The region between the thumb and the end of the track associated with the slider’s minimum value is drawn using the minimum track image. The region between the thumb and the end of the track associated with the slider’s maximum value is drawn using the maximum track image. Different track images are used to provide context as to which end contains the minimum Sliders Configuring Sliders 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 152
  • 153. value. You can customize their appearance by assigning different pairs of track images to each UIControlState of the slider. Assigning different images to each state lets you customize the appearance of the slider when it is enabled, disabled, highlighted, and so on. Use stretchable images for the slider’s track to create custom track images of any arbitrary width. You can create a stretchable image by using the UIImage method resizableImageWithCapInsets:. Use this method to add cap insets to an image or to change the existing cap insets of an image. During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the pixel area not covered by the cap in each direction is tiled, left-to-right and top-to-bottom, to resize the image. For best performance, use a single-pixel image. You can also customize the appearance of the thumb. Like the track images, you can assign different thumb images to each control state of the slider. To use a custom thumb image, add the image you wish to use to your Xcode project, and use it to create a UIImage. Use this UIImage to programmatically set the thumb image for your slider, as shown here. The same steps apply for the track images. UIImage *thumbImage = [UIImage imageNamed:@"custom_thumb.png"]; [self.mySlider setThumbImage:thumbImage forState:UIControlStateNormal]; Track and thumb images can only be customized programmatically, as there is no process for accomplishing this task in the Attributes Inspector. Using Auto Layout with Sliders You can create Auto Layout constraints between a slider and other user interface elements. You can create any type of constraint for a slider besides a baseline constraint. To keep a slider centered and adjust its width according to device orientation or screen size, you can use Auto Layout to pin it to its superview. Using the Auto Layout “Pin” menu, create “Leading Space to Superview” and “Trailing Space to Superview” constraints and set their values equal to each other. Doing this ensures that the endpoints of your slider are a specified distance from the edges of its superview. With these constraints, the slider stays centered and its width adjusts automatically for different device orientations and screen sizes. For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Sliders Using Auto Layout with Sliders 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 153
  • 154. Making Sliders Accessible Sliders are accessible by default. The default accessibility traits for a slider are User Interaction Enabled and Adjustable. When enabled on a device, VoiceOver speaks the accessibility label, value, traits, and hint are spoken back to the user. VoiceOver speaks this information when a user swipes up and down (not left and right) over the slider. For example, using the Ringer and Alerts volume slider (Settings > Sounds > Ringer and Alerts), VoiceOver speaks the following: "Sound volume: 13 percent. Adjustable. Swipe up or down with one finger to adjust the value." For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Internationalizing Sliders Sliders have no special properties related to internationalization. However, if you use a slider with a label, make sure you provide localized strings for the label. For more information, see Internationalization Programming Topics. Debugging Sliders When debugging issues with sliders, watch for these common pitfalls: ● Specifying conflicting appearance settings. When customizing slider appearance with images or tint, use one option or the other, but not both. Conflicting settings for track and thumb appearance will be resolved in favor of the most recently set value. For example, setting a new minimum track image for any state clears any custom tint color you may have provided for minimum track images. Similarly, setting the thumb tint color removes any custom thumb images associated with the slider. ● Selecting an out of range value. If you try to programmatically set a slider’s current value to be below the minimum or above the maximum, it is set to the minimum or maximum instead. However, if you try to do this using Interface Builder, the behavior is much different. For example, let's say your slider has a minimum value of 0, a maximum value of 5, and the current value is set to 1. If you change the current value to 999, the maximum value for the slider automatically changes to 999 because that value is higher than the maximum value, so Interface Builder adjusts accordingly. Sliders Making Sliders Accessible 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 154
  • 155. ● Not setting custom images for every control state. If you use custom track and thumb images for your slider, remember to set an image for every possible UIControlState. Any control state that does not have a corresponding custom image assigned to it will display the standard image instead. If you set one custom image, make sure to set them all. Elements Similar to a Slider The following elements provide similar functionality to a slider: ● Switch. A control that represents an on/off toggle button. You should use a switch instead of a slider when you want to give users a choice between two opposing, discrete options instead of a range of values. For more information, see “Switches” (page 161). ● Stepper. A control that uses a set of two buttons for incrementing or decrementing a value. You should use a stepper instead of a slider when you want to give users very precise control over the value of an element. For more information, see “Steppers” (page 156). Sliders Elements Similar to a Slider 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 155
  • 156. A stepper lets the user adjust a value by increasing and decreasing it in small steps. Steppers are used in situations where a user needs to adjust a value by a small amount. Steppers allow the user to: ● Make discrete and incremental adjustments to a value ● Have precise control over a value within a range Implementation: Steppers are implemented in the UIStepper class. For API reference, see UIStepper Class Reference. Configuring Steppers Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 156 Steppers
  • 157. You can customize the appearance of all steppers in your app using the appearance proxy (for example, [UIStepper appearance]), or just of a single control. For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Setting Stepper Values Configure a minimum, maximum, and current value for the stepper by setting these properties in Interface Builder. By default, a stepper’s minimum is set to 0, its maximum is set to 100, and its current value is set to 0. You can change these values by adjusting the Minimum (minimumValue), Maximum (maximumValue), and Current (value) fields. Steppers also allow you to specify step size, the amount by which the current value changes when the increase or decrease buttons are pressed. The default step size is 1. The corresponding Attributes Inspector field is called Step (stepValue). Specifying Stepper Behavior Steppers do not need a delegate to function properly; their parent view controller can define their behavior without implementing any delegate protocols. A stepper sends the UIControlEventValueChanged event when the user interacts it. You can respond to this event by performing some corresponding action in your app, such as adjusting music volume. You register the target-action methods for a page control as shown below. [self.myStepper addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; Alternatively, you can Control-drag the stepper’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). You can specify when a stepper’s UIControlEventValueChanged events are sent by toggling the “Continuous” (continuous) checkbox in the Attributes Inspector. In continuous delivery, the stepper sends multiple Value Changed events while the user keeps pressing on the stepper. In noncontinuous delivery, the stepper sends one Value Changed event when the user releases the stepper. Continuous control event delivery is enabled by default. Steppers Configuring Steppers 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 157
  • 158. A stepper defaults to autorepeat, which means that pressing and holding one of its buttons increments or decrements the stepper’s value repeatedly. The rate of change depends on how long the user continues pressing the control. The user can hold the stepper to quickly approach a desired value, and then increment or decrement to the desired value. Uncheck the “Autorepeat” (autorepeat) box if you want the stepper to be incremented or decremented one step at a time. You can set a stepper to wrap around to the minimum value when you try to increment it past its maximum—and vice versa. This functionality is disabled by default; to enable it, check the “Wrap” (wraps) box. Customizing Stepper Appearance You can customize the appearance of a stepper by setting the properties depicted below. To customize the appearance of all steppers in your app, use the appearance proxy (for example, [UIStepper appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Adjusting Stepper Tint Programmatically You can specify a custom stepper tint by setting the tintColor property programmatically. This property sets the color of the glyphs, divider, and border of the stepper. A translucent version of this color is also used to tint a stepper button when it is pressed down, as shown on the increment button below. Steppers Configuring Steppers 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 158
  • 159. If you do not explicitly set a tint color, the stepper will inherit its superview’s tint color. For more information, see “Adjusting View Tint Color” (page 19). Setting Stepper Glyphs The increment and decrement images are the glyphs that sit on top of each stepper button. They appear on top of the background image. Use the setDecrementImage:forState: and setIncrementImage:forState: methods to specify custom increment and decrement images for each control state. Note that an increment or decrement image will be automatically rendered as a template image within a toolbar, unless you explicitly set its rendering mode to UIImageRenderingModeAlwaysOriginal. For more information, see “Using Template Images” (page 19). Setting Stepper Images You can set custom images for each UIControlState of a stepper. For more information about control states, see “Understanding Control States” (page 117). A stepper can have a background image that covers the entirety of the control except for the divider, filling the entire frame of the stepper. Use the backgroundImageForState: method to set a background image for each control state of the stepper. To strengthen the visual effect of a stepper button being pressed, you can set custom divider images for different combinations of button states: increment button pressed, decrement button pressed, and neither pressed. Note that it is impossible to press both buttons at the same time. Use the setDividerImage:forLeftSegmentState:rightSegmentState: method to specify custom divider images. Don’t forget to set an image for every state. Using Auto Layout with Steppers You can create Auto Layout constraints between a stepper and other user interface elements. You can create any type of constraint for a stepper besides a baseline constraint. For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Making Steppers Accessible Steppers are accessible by default. The default accessibility traits for a stepper are User Interaction Enabled and Adjustable. Steppers Using Auto Layout with Steppers 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 159
  • 160. For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Internationalizing Steppers Steppers have no special properties related to internationalization. However, if you use a stepper with a label, make sure you provide localized strings for the label. For more information, see Internationalization Programming Topics. Elements Similar to a Stepper The following elements provide similar functionality to a stepper: ● Slider. Use sliders to adjust a value continuously, rather than in discrete steps. Sliders are more appropriate than steppers for setting a value that has a large range. For more information, see “Sliders” (page 149). ● Picker View. Use pickers to let the user select one of a list of options, rather than stepping through the range of a value. A picker is more appropriate when selecting from a fixed set of options—for example, choosing a month. For more information, see “Picker Views” (page 62). Steppers Internationalizing Steppers 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 160
  • 161. A switch lets the user turn an option on and off. You see switches used throughout the Settings app to let a user quickly toggle a specific setting. Switches allow the user to: ● Choose between two mutually exclusive options ● Quickly toggle an option on and off Implementation: Sliders are implemented in the UISwitch class and discussed in the UISwitch. Configuring Switches Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 161 Switches
  • 162. Setting Switch Value Specify a switch’s state to indicate whether the switch is initially on or off. The default value is on. Use the State (on) field in the Attributes Inspector to accomplish this task. Specifying Switch Behavior Programmatically Switches do not need a delegate to function properly; their parent view controller can define their behavior without implementing any delegate protocols. A switch sends the UIControlEventValueChanged event when the user toggles it. You can respond to this event by performing some corresponding action in your app, such as turning a setting on or off. You register the target-action methods for a switch as shown below. [mySwitch addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged]; Alternatively, you can Control-drag the switch’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). Customizing Switch Appearance You can customize the appearance of a switch by setting the properties depicted below. To customize the appearance of all switches in your app, use the appearance proxy (for example, [UISwitch appearance]). For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Switches Configuring Switches 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 162
  • 163. Adjusting Switch Tint A switch’s on tint can be configured in the On Tint (onTintColor) field in Attributes Inspector. This is the color you see when a switch is in the on position. The default on tint is green. Thumb tint and off tint can only be configured programmatically. By default, the thumb tint is white and can be set using the thumbTintColor property . You can also set a custom off tint using the tintColor property. The off tint is light gray by default, but will inherit its superview’s tint color if a custom one is set. For more information, see “Adjusting View Tint Color” (page 19). self.mySwitch.thumbTintColor = [UIColor blueColor]; self.mySwitch.tintColor = [UIColor redColor]; Using Auto Layout with Switches Switches need a label to tell the user what they are for. To label a switch, drag a label out of the elements library. Make a bottom alignment constraint between their baselines, and a horizontal space constraint between them of standard size. For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Making Switches Accessible Switches are accessible by default. A switch’s default accessibility traits are Button and User Interaction Enabled. Switches are typically used in a table cell. When a table cell with a switch is tapped, VoiceOver speaks the cell name, state of the switch, and hint are spoken back to the user. For example, when a user taps the Invert Colors switch (Settings > General > Accessibility), VoiceOver speaks the following: Invert Colors. Off. Double tap to toggle setting. For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Switches Using Auto Layout with Switches 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 163
  • 164. Internationalizing Switches Switches have no special properties related to internationalization. However, if you use a switch with a label, make sure you provide localized strings for the label. For more information, see Internationalization Programming Topics. Debugging Switches When debugging issues with sliders, watch for these common pitfalls: ● Setting on/off images that are the wrong dimensions. A switch does not scale or stretch any custom images that you add to it. For example, if you specify an on image that is smaller than the switch, you will see the switch’s on tint color in the space that’s not covered by the image. On the other hand, if you specify an on image that is too big, it can bleed over into the space intended for the off image. The size of on/off images should be 77 points wide and 27 points tall. ● Specifying conflicting appearance settings. When customizing switch appearance with images or tint, you can use one option or the other, but not both. Custom images appear on top of the tint layer. While you may think you are adjusting the tint of the image itself, you’re simply setting the tint for a layer that is not visible under the image. Elements Similar to a Switch The following element provides similar functionality to a switch: Slider. A control that allows users to make adjustments to a value within a range of value. You should use a slider instead of a switch when you want to let users select from a range of values instead of giving them a choice between two opposing, discrete options. For more information, see “Sliders” (page 149). Switches Internationalizing Switches 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 164
  • 165. Text fields allows the user to input a single line of text into an app. You typically use text fields to gather small amounts of text from the user and perform some immediate action, such as a search operation, based on that text. Text fields allow the user to: ● Enter text as input to an app Implementation: Text fields are implemented in the UITextField class and discussed in the UITextField Class Reference. Configuring Text Fields Generally, the easiest way to configure controls—namely, their content, behavior, and appearance—is by using the Attributes Inspector in Interface Builder. As an alternative to using the Attributes Inspector, you can set some configurations programmatically. A few configurations cannot be made through the Attributes Inspector, so you must make them programmatically. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 165 Text Fields
  • 166. Setting Text Field Content Set the content of the text field using the Text (text) field. You can select whether you want plain or attributed text. The placeholder appears in place whenever a text field has no characters (before a user begins typing, or if the user deletes everything in the text field). Both placeholder and text can be attributed strings. For information about using attributed text, see “Specifying Text Appearance” (page 168). A user can use the Clear button to delete all text in the text field, and display the placeholder string if one is set. You can specify when the Clear button is displayed to the user using the Clear Button (clearButtonMode) field. Additionally, you can indicate whether the text field should automatically clear itself when the user begins editing it by checking the Clear When Editing Begins (clearsOnBeginEditing) box. Note: The Clear button only appears when there is text shown in the text field, not the placeholder. Even if you select the “Is always visible” option, it will not appear when only placeholder text appears. Specifying Text Field Behavior Text fields need a delegate to handle any custom behaviors, such as displaying additional overlay views when a user begins editing it. By assigning the parent view controller as the text field’s delegate and implementing any or all of the UITextFieldDelegate methods, you can implement such custom behaviors. A text field sends the UIControlEventEditingDidBegin, UIControlEventEditingChanged, UIControlEventEditingDidEnd, and UIControlEventEditingDidEndOnExit events when the user edits it. You can respond to these events by performing some corresponding action in your app, such as updating information as the user types it. You register the target-action methods for a text field as shown below. [self.myTextField addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventEditingDidEnd]; Text Fields Configuring Text Fields 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 166
  • 167. Alternatively, you can Control-drag the text field’s Value Changed event from the Connections Inspector to the action method. For more information, see “Understanding the Target-Action Mechanism” (page 118). A user types content into a text field using a keyboard, which has a number of customization options: ● Keyboard layout. The Keyboard field allows you to select from a number of different keyboard layouts. Match the keyboard layout to the purpose of the text field. If the user will be entering a web address, select the URL keyboard. The default keyboard layout is an alphanumeric keyboard in the device’s default language. For a list of possible keyboard types, see UIKeyboardType. You cannot customize the appearance of the keyboard on iOS 7. ● Return key. The return key, which appears in the bottom right of the keyboard, allows the user to notify the system when they are finished editing the text field. You can select one of several standard return key types by using the Return Key field. The return key is disabled by default, and only becomes enabled when a user types something into the text field. If you want your user to be able to press the return key any time the keyboard is open, even if the input is empty or incomplete, you can enable the Auto-enable Return Key option. Different return keys are intended to provide the user with an understanding of what action hitting the key will trigger. Note that simply selecting a different return key appearance does not provide you with the functionality intended by that key; you must implement custom return key behavior yourself using the textFieldShouldReturn: method in your text field’s delegate. ● Capitalization scheme. The Capitalization field specifies how text should be capitalized in the text field: no capitalization, every word, every sentence, or every character. Although no capitalization is selected by default, you should select the capitalization scheme that reflects the intended use of your text field. For example, if you ask for a user’s full name, you can configure the keyboard to capitalize every word so the user does not have to do it manually. ● Auto-correction. The Correction field simply disables or enables auto-correct in the text field. ● Secure content. The Secure option is off by default. Enabling it causes the text field to obscure text once it is typed, allowing the user to safely enter secure content—such as a password—into the field. You can use the text field delegate methods to handle custom keyboard dismissal. Text Fields Configuring Text Fields 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 167
  • 168. Customizing Text Field Appearance You can customize the appearance of a text field by setting the properties depicted below. To customize the appearance of all text fields in your app, use the appearance proxy (for example, [UITextField appearance]), or just of a single control. For more information about appearance proxies, see “Using Appearance Proxies” (page 18). Selecting Border Style You can select one of the following border styles for your text field by selecting it next to the Border Style (borderStyle) field: Specifying Text Appearance Text views can have one of two types of text: plain or attributed. Plain text supports a single set of formatting attributes—font, size, color, and so on—for the entire string. On the other hand, attributed text supports multiple sets of attributes that apply to individual characters or ranges of characters in the string. Text Fields Configuring Text Fields 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 168
  • 169. Specifying Font Size By default, the Adjusts to Fit (adjustsFontSizeToFitWidth) box is selected in the Attributes Inspector. When this option is enabled, the font size of your text label will automatically scale to fit inside the text field. If you anticipate your text label to change—such as if the string is localized—you should keep this selected. Setting a minimum font size ensures that your text will never appear smaller than intended. Use the Min Font Size (minimumFontSize) field if you want to change the value from its default. Using Images in Text Fields A text field can have a background image that sits under the content of the text field. Use the Background (background) field to set a background image for the normal state and the Disabled (disabledBackground) field to set a background image for when the control is disabled. Using Auto Layout with Text Fields You can create Auto Layout constraints between a text field and other user interface elements. You can create any type of constraint for a text field. You will generally need to specify what a text field is intended for. You can use a label to do this. Place the label to the left of the text field and give the label and text field a “Horizontal Spacing” constraint. For general information about using Auto Layout with iOS controls, see “Using Auto Layout with Controls” (page 120). Making Text Fields Accessible Text fields are accessible by default. The default accessibility traits for a text field are User Interaction Enabled and Adjustable. For general information about making iOS controls accessible, see “Making Controls Accessible” (page 121). Text Fields Using Auto Layout with Text Fields 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 169
  • 170. Internationalizing Text Fields The default language of the device affects the keyboard that pops up with the text field (including the return key). You don’t need to do anything to enable this functionality; it is enabled by default. However, your text field should be able to handle input that comes from any language. For more information, see Internationalization Programming Topics. Elements Similar to a Text Field The following elements provide similar functionality to a text field: ● Text View. A text view accepts and displays multiple lines of text. Text views support scrolling and text editing. You typically use a text view to display a large amount of text, such as the body of an email message. For more information, see “Text Views” (page 98). ● Label. A label displays static text. Labels are often used in conjunction with controls to describe their intended purpose, such as explaining which value a button or slider affects. For more information, see “Labels” (page 49). Text Fields Internationalizing Text Fields 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 170
  • 171. Important: This is a preliminary document for an API or technology in development. Although this document has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only by registered members of the applicable Apple Developer program. Apple is supplying this confidential information to help you plan for the adoption of the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be tested with final operating system software and final documentation. Newer versions of this document may be provided with future seeds of the API or technology. ● “Activity Indicator View” (page 173) ● “Bar Button Item” (page 175) ● “Bar Item” (page 178) ● “Button” (page 179) ● “Collection Reusable View” (page 185) ● “Collection View” (page 186) ● “Collection View Cell” (page 188) ● “Control” (page 189) ● “Date Picker” (page 191) ● “Image View” (page 194) ● “Label” (page 195) ● “Navigation Bar” (page 200) ● “Navigation Item” (page 201) ● “Page Control” (page 202) ● “Picker View” (page 204) ● “Progress View” (page 205) ● “Scroll View” (page 206) ● “Scroll View” (page 206) ● “Search Bar” (page 211) ● “Segmented Control” (page 215) 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 171 Attributes Inspector Reference
  • 172. ● “Slider” (page 218) ● “Stepper” (page 220) ● “Switch” (page 222) ● “Tab Bar” (page 223) ● “Tab Bar Item” (page 224) ● “Table View” (page 225) ● “Table View Cell” (page 227) ● “Text View” (page 231) ● “Toolbar” (page 238) ● “View” (page 239) ● “Web View” (page 243) Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 172
  • 173. Important: This is a preliminary document for an API or technology in development. Although this document has been reviewed for technical accuracy, it is not final. This Apple confidential information is for use only by registered members of the applicable Apple Developer program. Apple is supplying this confidential information to help you plan for the adoption of the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be tested with final operating system software and final documentation. Newer versions of this document may be provided with future seeds of the API or technology. Activity Indicator View Attributes Inspector Reference Appearance and Behavior Style The basic appearance of the activity indicator. ArgumentMethodSelection UIActivityIndicator- ViewStyleWhiteLarge activityIndicatorViewStyleLarge White UIActivityIndicatorViewStyleWhiteactivityIndicatorViewStyleWhite UIActivityIndicatorViewStyleGrayactivityIndicatorViewStyleGray Color The color of the activity indicator. Access: color Behavior Animating 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 173 Activity Indicator View
  • 174. Whether the activity indicator is moving. Access: isAnimating MethodSelection stopAnimatingUnselected startAnimatingSelected Hides When Stopped Whether the activity indicator is not shown when it is not animating. ArgumentMethodSelection NOhidesWhenStoppedUnselected YEShidesWhenStoppedSelected Activity Indicator View Activity Indicator View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 174
  • 175. Bar Button Item Attributes Inspector Reference Appearance Style The bar button item style. ArgumentMethodSelection UIBarButtonItemStylePlainstylePlain UIBarButtonItemStyleBorderedstyleBordered UIBarButtonItemStyleDonestyleDone Identifier The button type of the bar button item. To specify a custom button, use initWithTitle:image:tag: or image. ArgumentMethodSelection Custom UIBarButtonSystem- ItemFlexibleSpace initWithBarButtonSystemItem: target:action: Flexible Space UIBarButtonSystem- ItemFixedSpace initWithBarButtonSystemItem: target:action: Fixed Space UIBarButtonSystemItemAddinitWithBarButtonSystemItem: target:action: Add UIBarButtonSystemItemEditinitWithBarButtonSystemItem: target:action: Edit 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 175 Bar Button Item
  • 176. ArgumentMethodSelection UIBarButtonSystemItemDoneinitWithBarButtonSystemItem: target:action: Done UIBarButtonSystemItemCancelinitWithBarButtonSystemItem: target:action: Cancel UIBarButtonSystemItemSaveinitWithBarButtonSystemItem: target:action: Save UIBarButtonSystemItemUndoinitWithBarButtonSystemItem: target:action: Undo UIBarButtonSystemItemRedoinitWithBarButtonSystemItem: target:action: Redo UIBarButtonSystem- ItemCompose initWithBarButtonSystemItem: target:action: Compose UIBarButtonSystemItemReplyinitWithBarButtonSystemItem: target:action: Reply UIBarButtonSystemItemActioninitWithBarButtonSystemItem: target:action: Action UIBarButtonSystem- ItemOrganize initWithBarButtonSystemItem: target:action: Organize UIBarButtonSystemItemTrashinitWithBarButtonSystemItem: target:action: Trash UIBarButtonSystem- ItemBookmarks initWithBarButtonSystemItem: target:action: Bookmarks UIBarButtonSystemItemSearchinitWithBarButtonSystemItem: target:action: Search UIBarButtonSystem- ItemFlexibleSpace initWithBarButtonSystemItem: target:action: Refresh UIBarButtonSystemItemStopinitWithBarButtonSystemItem: target:action: Stop UIBarButtonSystemItemCamerainitWithBarButtonSystemItem: target:action: Camera Bar Button Item Bar Button Item Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 176
  • 178. Bar Item Attributes Inspector Reference Appearance, Behavior, and Tagging Title The bar item title. Access: title. Image The bar item image. Access: image. Tag The bar item tag. Access: tag. Enabled Whether the bar item is enabled. ArgumentMethodSelection NOenabledUnselected YESenabledSelected 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 178 Bar Item
  • 179. Button Attributes Inspector Reference Type Type The button type, which determines its functionality. ArgumentMethodSelection UIButtonTypeCustombuttonTypeCustom UIButtonTypeRoundedRectbuttonTypeRounded Rect UIButtonTypeDetailDisclosurebuttonTypeDetail Disclosure UIButtonTypeInfoLightbuttonTypeInfo Light UIButtonTypeInfoDarkbuttonTypeInfo Dark UIButtonTypeContactAddbuttonTypeAdd Contact Appearance This group specifies the appearance of the button in each of its possible states. State Config The button state to configure. Choose a state, and then configure the remaining properties in this group. The settings are applied to those properties when the button goes to that state. ArgumentMethodSelection UIControlStateNormalstateDefault 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 179 Button
  • 180. ArgumentMethodSelection UIControlStateHighlightedstateHighlighted UIControlStateSelectedstateSelected UIControlStateDisabledstateDisabled Title Title Type The type of text to use for the button title when the button is in the state identified by State Config. Selection Plain Attributed Title Type: Plain These are the properties you can configure for plain text titles in the state identified by State Config. Text The plain text for the button title in the state identified by State Config. Access: titleForState:, setTitle:forState:. Font The font for the button plain text title in the state identified by State Config. Use <button>.titleLabel.font to access the value of this property. Text Color The color for the button plain text title in the state identified by State Config. Access: titleColorForState:, setTitleColor:forState:. Shadow Color The color for the button plain text title in the state identified by State Config. Button Button Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 180
  • 181. Access: titleShadowColorForState:, setTitleShadowColor:forState:. Title Type: Attributed These are the properties you can configure for attributed text titles in the state identified by State Config. Attributed Title Layout The alignment and other layout characteristics for the button attributed text title in the state identified by State Config. You can set these layout characteristics: alignment (left, center, right, justified, and natural), text color, background color, text direction, line breaking, line height and spacing, paragraph spacing, indentation, hyphenation, truncation, and header level). Selection Left Center Right Justified Natural Text Color Background Color More Font The font for the button attributed text title in the state identified by State Config. Access: button.titleLabel.font. Attributed Text The attributed text for the button title in the state identified by State Config. Access: attributedTitleForState:. Image Button Button Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 181
  • 182. The image for the button when it is in the state identified by State Config. Access: imageForState:, setImage:forState:. Background The background image for the button when it is in the state identified by State Config. Access: backgroundImageForState:, setBackgroundImage:forState:. Behavior Shadow Offset Offset Size The width and height of the shadow of the button title. Access: titleShadowOffset. Reverses On Highlight Whether the shadow of the button title changes when the button state changes to or from highlighted. ArgumentMethodSelection NOreversesTitleShadowWhenHighlightedUnselected YESreversesTitleShadowWhenHighlightedSelected Highlight Tint The color for the button tint. tintColor Drawing Shows Touch On Highlight Whether the button glows when it is tapped. ArgumentMethodSelection NOshowsTouchWhenHighlightedUnselected Button Button Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 182
  • 183. ArgumentMethodSelection YESshowsTouchWhenHighlightedSelected Highlighted Adjusts Image Whether the button image changes when the button state changes to or from highlighted. ArgumentMethodSelection NOadjustsImageWhenHighlightedUnselected YESadjustsImageWhenHighlightedSelected Disabled Adjusts Image Whether the button image changes when the button state changes to or from disabled. ArgumentMethodSelection NOadjustsImageWhenDisabledUnselected YESadjustsImageWhenDisabledSelected Line Break The line break mode for the button title. ArgumentMethodSelection UILineBreakModeCliplineBreakModeClip UILineBreakModeCharacterWraplineBreakModeCharacter Wrap UILineBreakModeWordWraplineBreakModeWord Wrap UILineBreakModeHeadTruncationlineBreakModeTruncate Head UILineBreakModeMiddleTruncationlineBreakModeTruncate Middle UILineBreakModeTailTruncationlineBreakModeTruncate Tail Button Button Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 183
  • 184. Edge Insets Edge insets resize and reposition the effective drawing rectangle for the button’s entire content, its title, and its image. Edge The button edge to configure. Selection Content Title Image Inset The inset or outset margins of the rectangle identified by the Edge property. You can specify a value for each the edges (top, left, bottom, right). A positive value shrinks (or insets) the corresponding edge, moving it closer to the center of the button. A negative value expands (or outsets) the corresponding edge. Access: contentEdgeInsets, titleEdgeInsets, imageEdgeInsets. Button Button Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 184
  • 185. Collection Reusable View Attributes Inspector Reference Cell Reuse Identifier The collection reusable view reuse identifier. Access: reuseIdentifier. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 185 Collection Reusable View
  • 186. Collection View Attributes Inspector Reference Layout, Scrolling, Header, and Footer Layout The layout to use to lay out the collection view content. Access: collectionViewLayout Selection Flow Custom Layout: Flow Scroll Direction The direction along which the collection view scrolls. Access: collection_view.collectionViewLayout.scrollDirection ArgumentMethodSelection UICollectionViewScrollDirectionVerticalscrollDirectionVertical UICollectionViewScrollDirectionHorizontalscrollDirectionHorizontal Accessories Section Header Whether the collection view has a header. Access: collection_view.collectionViewLayout.headerReferenceSize headerReferenceSize. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 186 Collection View
  • 187. CodeSelection collection_view.collectionViewLayout.headerReferenceSize = 0.0 Unselected collection_view.collectionViewLayout.headerReferenceSize = // Floating-point value greater than 0.0 Selected Section Footer Whether the collection view has a footer. Access: collection_view.collectionViewLayout.footerReferenceSize footerReferenceSize. CodeSelection collection_view.collectionViewLayout.footerReferenceSize = 0.0 Unselected collection_view.collectionViewLayout.footerReferenceSize = // Floating-point value greater than 0.0 Selected Layout: Custom Class The class of the layout to use to lay out the collection view content. Collection View Collection View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 187
  • 188. Collection View Cell Attributes Inspector Reference Cell Reuse Identifier The collection view cell reuse identifier. Access: reuseIdentifier. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 188 Collection View Cell
  • 189. Control Attributes Inspector Reference Layout Alignment Horizontal The horizontal alignment of the content. ArgumentMethodSelection UIControlContentHorizontalAlignment- Left contentHorizontalAlignmentLeft UIControlContentHorizontalAlignment- Center contentHorizontalAlignmentCenter UIControlContentHorizontalAlignment- Right contentHorizontalAlignmentRight UIControlContentHorizontalAlignment- Fill contentHorizontalAlignmentFill Vertical The vertical alignment of the content. ArgumentMethodSelection UIControlContentVerticalAlignmentTopcontentVerticalAlignmentTop UIControlContentVerticalAlignmentCentercontentVerticalAlignmentCenter UIControlContentVerticalAlignmentBottomcontentVerticalAlignmentBottom UIControlContentVerticalAlignmentFillcontentVerticalAlignmentFill 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 189 Control
  • 190. Behavior Content Selected Whether the control is selected. ArgumentMethodSelection NOselectedUnselected YESselectedSelected Enabled Whether the user can interact with the control. ArgumentMethodSelection NOenabledUnselected YESenabledSelected Highlighted Whether the control is highlighted. ArgumentMethodChoice NOhighlightedUnselected YEShighlightedSelected Control Control Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 190
  • 191. Date Picker Attributes Inspector Reference Functionality Mode The functionality of the date picker. The mode indicates whether the date picker is a date or time picker, or a count down timer. ArgumentMethodSelection UIDatePickerModeTimedatePickerModeTime UIDatePickerModeDatedatePickerModeDate UIDatePickerModeDateAndTimedatePickerModeDate and Time UIDatePickerModeCountDownTimerdatePickerModeCount Down Timer Locale The locale for the date picker. Access: locale. Interval The interval at which the date picker displays minutes. Access: minuteInterval. Selection 1 minute 2 minutes 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 191 Date Picker
  • 192. Selection 3 minutes 4 minutes 5 minutes 6 minutes 10 minutes 12 minutes 15 minutes 20 minutes 30 minutes Date These properties are unused when the date picker mode is count down timer. Date The date the date picker displays. Access: date. Constraints Minimum Date The earliest date the date picker displays. Access: minimumDate. Maximum Date The latest date the date picker displays. Access: maximumDate. Date Picker Date Picker Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 192
  • 193. Count Down Timer Count Down in Seconds The number of seconds from which the date picker counts down. Access: countDownDuration. Date Picker Date Picker Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 193
  • 194. Image View Attributes Inspector Reference Images The properties in this group are not used when you specify an image sequence using animationImages. Image The image displayed in the image view when its state is not highlighted. Access: image. Highlighted The image displayed in the image view when its state is highlighted. Access: highlightedImage. Behavior State Highlighted Whether the image view is highlighted. Toggle this property after setting Image and Highlighted to preview the images for each state. ArgumentMethodSelection NOhighlightedUnselected YEShighlightedSelected 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 194 Image View
  • 195. Label Attributes Inspector Reference Text and Behavior Text Text Type The type of the label text. Selection Plain Attributed Text Type: Plain This group configures the label plain text. Text The label plain text. Access: text. Color The color of the label plain text. Access: textColor. Font The font of the label plain text. Access: font. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 195 Label
  • 196. Alignment The alignment of the label plain text. ArgumentMethodSelection NSTextAlignmentLefttextAlignmentLeft NSTextAlignmentCentertextAlignmentCenter NSTextAlignmentRighttextAlignmentRight Text Type: Attributed This group configures the text selected in Attributed Text. Attributed Text Layout The alignment and other layout characteristics of the selected attributed text. To set alignment and other layout characteristics of part of the attributed text in code, you need to create an attributed string with the desired characteristics and assign it to attributedText. Selection Left Center Right Justified Natural Text Color Background Color More Font The font of the selected attributed text. Access: font. Label Label Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 196
  • 197. Attributed Text The label attributed text. Access: attributedText. Lines The maximum number of lines for the label text. Set to 0 for an unlimited number of lines. Access: numberOfLines. Behavior Enabled Whether the label is enabled. ArgumentMethodSelection NOenabledUnselected YESenabledSelected Highlighted Whether the label is highlighted. Toggle this property after setting the text highlight color to preview the highlighted label. ArgumentMethodSelection NOhighlightedUnselected YEShighlightedSelected Text Baseline and Line Breaks Baseline How to adjust the text baseline so that the text fits in the label. Label Label Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 197
  • 198. ArgumentMethodSelection UIBaselineAdjustmentAlignBaselinesbaselineAdjustmentAlign Baselines UIBaselineAdjustmentAlignCentersbaselineAdjustmentAlign Centers UIBaselineAdjustmentNonebaselineAdjustmentNone Line Breaks The line break mode of the label text. ArgumentMethodSelection UILineBreakModeCliplineBreakModeClip UILineBreakModeCharacterWraplineBreakModeCharacter Wrap UILineBreakModeWordWraplineBreakModeWord Wrap UILineBreakModeHeadTruncationlineBreakModeTruncate Head UILineBreakModeMiddleTruncationlineBreakModeTruncate Middle UILineBreakModeTailTruncationlineBreakModeTruncate Tail Text Sizing Autoshrink How to shrink the label text so that it fits in the label. MethodArgumentMethodSelection NOadjustsFontSize- ToFitWidth Fixed Font Size minimumScaleFactorYESadjustsFontSize- ToFitWidth Minimum Font Scale minimumFontSizeYESadjustsFontSize- ToFitWidth Minimum Font Size Tighten Letter Spacing Label Label Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 198
  • 199. Whether to reduce the label text letter spacing so that it fits in the label. ArgumentMethodSelection NOadjustsLetterSpacingToFitWidthUnselected YESadjustsLetterSpacingToFitWidthSelected Text Highlight and Shadow Highlighted The color for the label text when the label is highlighted. This property applies only to plain text labels. Access: highlightedTextColor. Shadow The color of the label text shadow. Access: shadowColor. Shadow Offset The offset of the label text shadow. Access: shadowOffset. Label Label Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 199
  • 200. Navigation Bar Attributes Inspector Reference Appearance Style The basic appearance of the navigation bar. ArgumentMethodSelection UIBarStyleDefaultbarStyleDefault UIBarStyleBlackbarStyleBlack Opaque UIBarStyleBlackTranslucentbarStyleBlack Translucent Tint The color of the navigation bar. Access: tintColor. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 200 Navigation Bar
  • 201. Navigation Item Attributes Inspector Reference PropertyGroup Title The navigation item title. Access: title. Prompt The navigation item prompt. Access: prompt. Back Button The bar button item the navigation item displays when it needs a back button. Access: backBarButtonItem. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 201 Navigation Item
  • 202. Page Control Attributes Inspector Reference Behavior and Pages Number of Pages The number of pages the page control shows. Access: numberOfPages Current The index of the page control current page. Access: currentPage Behavior Hides for Single Page Whether the page control is hidden when the number of pages is 1. ArgumentMethodChoice NOhidesForSinglePageUnselected YEShidesForSinglePageSelected Defers Page Display Whether the page control defers updating its display when the user selects a page. When display-update is deferred, the page control does not update its display when the user selects a page. To update the display, call updateCurrentPageDisplay. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 202 Page Control
  • 203. ArgumentMethodChoice NOdefersCurrentPageDisplayUnselected YESdefersCurrentPageDisplaySelected Appearance Tint Color The color of the page control dots that correspond to non-open pages. Access: pageIndicatorTintColor Current Page The color of the page control dot that corresponds to the currently open page. Access: currentPageIndicatorTintColor Page Control Page Control Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 203
  • 204. Picker View Attributes Inspector Reference Behavior Shows Selection Indicator Whether the picker view shows the bar that identifies the selected row in each component. ArgumentMethodSelection NOshowsSelectionIndicatorUnselected YESshowsSelectionIndicatorSelected 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 204 Picker View
  • 205. Progress View Attributes Inspector Reference Appearance and Progress Style The basic appearance of the progress view. ArgumentMethodSelection UIProgressViewStyleDefaultprogressViewStyleDefault UIProgressViewStyleBarprogressViewStyleBar Progress The progress view progress. Access: progress. Progress Tint The color of the progress view completed-progress bar. Access: progressTintColor. Track Tint The color of the progress view track. Access: trackTintColor. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 205 Progress View
  • 206. Scroll View Attributes Inspector Reference Appearance Style The appearance of the scroll view scroll indicators. ArgumentMethodSelection UIScrollViewIndicatorStyleDefaultindicatorStyleDefault UIScrollViewIndicatorStyleBlackindicatorStyleBlack UIScrollViewIndicatorStyleWhiteindicatorStyleWhite Scroll Indicators and Scrolling Scrollers Shows Horizontal Scrollers Whether the scroll view horizontal scroll indicator is visible. ArgumentMethodSelection NOshowsHorizontalScrollIndicatorUnselected YESshowsHorizontalScrollIndicatorSelected Shows Vertical Scrollers Whether the scroll view vertical scroll indicator is visible. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 206 Scroll View
  • 207. ArgumentMethodSelection NOshowsVerticalScrollIndicatorUnselected YESshowsVerticalScrollIndicatorSelected Scrolling Enabled Whether the user can scroll the scroll view contents. When scrolling is enabled the user can scroll the scroll view contents. ArgumentMethodSelection NOscrollEnabledUnselected YESscrollEnabledSelected Paging Enabled Whether the scroll view stops at regular intervals as the user scrolls. When paging is enabled the scroll view stops on multiples of the scroll view bounds as the user scrolls. ArgumentMethodSelection NOpagingEnabledUnselected YESpagingEnabledSelected Direction Lock Enabled Whether the user can scroll in only one cardinal direction at a time. When direction lock is enabled the user can scroll in only one cardinal direction at a time, vertically or horizontally, except when the user scrolls diagonally. ArgumentMethodSelection NOdirectionalLockEnabledUnselected YESdirectionalLockEnabledSelected Scroll View Scroll View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 207
  • 208. Scroll Bounce Bounce Bounces Whether the scroll view bounces when the user scrolls past a content edge. ArgumentMethodSelection NObouncesUnselected YESbouncesSelected Bounce Horizontally Whether the scroll view bounces when the user scrolls past a horizontal content edge. When horizontal bouncing is allowed, the scroll view lets the user scroll horizontally even when the scroll view content does not fill the scroll view bounds horizontally. ArgumentMethodSelection NOalwaysBounceHorizontalUnselected YESalwaysBounceHorizontalSelected Bounce Vertically Whether the scroll view bounces when the user scrolls past a vertical content edge. When vertical bouncing is allowed, the scroll view lets the user scroll vertically even when the scroll view content does not fill the scroll view bounds vertically. ArgumentMethodSelection NOalwaysBounceVerticalUnselected YESalwaysBounceVerticalSelected Scroll View Scroll View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 208
  • 209. Zooming Zoom Min The minimum zoom scale factor the user can apply to the scroll view content. Access: minimumZoomScale. Max The maximum zoom scale factor the user can apply to the scroll view content. Access: maximumZoomScale. Events and Zoom Bounce Touch Bounces Zoom Whether the scroll view bounces when the user zooms past the scroll view minimum or maximum zoom scale factors. ArgumentMethodSelection NObouncesZoomUnselected YESbouncesZoomSelected Delays Content Touches Whether the scroll view delays the handling of every touch event to determine whether the event is a scrolling event. ArgumentMethodSelection NOdelaysContentTouchesUnselected YESdelaysContentTouchesSelected Cancellable Content Touches Whether the scroll view can convert a touch event into a scroll event to reflect user intent. Scroll View Scroll View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 209
  • 210. When content touches are cancellable, the view can cancel the handling of a touch event and initiate a scroll event when the user drags. ArgumentMethodSelection NOcanCancelContentTouchesUnselected YEScanCancelContentTouchesSelected Scroll View Scroll View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 210
  • 211. Search Bar Attributes Inspector Reference Search Term and Captions Text The initial search string. Access: text. Placeholder The text that appears when there is no search string. Access: placeholder. Prompt The text that appears above the text field. Access: prompt. Appearance Style The basic appearance of the search bar. ArgumentMethodSelection UIBarStyleDefaultbarStyleDefault UIBarStyleBlackbarStyleBlack Opaque UIBarStyleBlackTranslucentbarStyleBlack Translucent 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 211 Search Bar
  • 212. Tint The color of the search bar. Access: tintColor. Capabilities Shows Search Results Button Whether the search bar displays the Search Results button. ArgumentMethodSelection NOshowsSearchResultsButtonUnselected YESshowsSearchResultsButtonSelected Shows Bookmarks Button Whether the search bar displays the Bookmarks button. ArgumentMethodSelection NOshowsBookmarkButtonUnselected YESshowsBookmarkButtonSelected Shows Cancel Button Whether the search bar displays the Cancel button. ArgumentMethodSelection NOshowsCancelButtonUnselected YESshowsCancelButtonSelected Shows Scope Bar Whether the search bar displays the scope bar. Search Bar Search Bar Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 212
  • 213. ArgumentMethodSelection NOshowsScopeBarUnselected YESshowsScopeBarSelected Scope Titles Scope Title List The titles of the scope buttons in the scope bar. Access: scopeButtonTitles. Text Input Capitalize Whether and when the keyboard activates the Shift key while the user types text. ArgumentMethodSelection UITextAutocapitalizationTypeNoneautocapitalizationTypeNone UITextAutocapitalizationTypeWordsautocapitalizationTypeWords UITextAutocapitalizationTypeSentencesautocapitalizationTypeSentences UITextAutocapitalization- TypeAllCharacters autocapitalizationTypeAll Characters Correction Whether to auto-correct text the user types. ArgumentMethodSelection UITextAutocorrectionTypeDefaultautocorrectionTypeDefault UITextAutocorrectionTypeNoautocorrectionTypeNo UITextAutocorrectionTypeYesautocorrectionTypeYes Search Bar Search Bar Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 213
  • 214. Keyboard The type of keyboard that appears on text input. ArgumentMethodSelection UIKeyboardTypeDefaultkeyboardTypeDefault UIKeyboardTypeASCIICapablekeyboardTypeASCII Capable UIKeyboardTypeNumbersAndPunctuationkeyboardTypeNumbers and Punctuation UIKeyboardTypeURLkeyboardTypeURL UIKeyboardTypeNumberPadkeyboardTypeNumber Pad UIKeyboardTypePhonePadkeyboardTypePhone Pad UIKeyboardTypeEmailAddresskeyboardTypeE-mail Address Search Bar Search Bar Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 214
  • 215. Segmented Control Attributes Inspector Reference Appearance and Behavior This group specifies the appearance and behavior for the segmented control. Style The basic appearance of the segmented control. ArgumentMethodSelection UISegmentedControlStylePlainsegmentedControlStylePlain UISegmentedControlStyleBorderedsegmentedControlStyleBordered UISegmentedControlStyleBarsegmentedControlStyleBar State Momentary Whether the segmented control segments are only momentarily selected. A segmented control selection behavior can be normal or momentary. ● Normal selection. When the user taps a segment, the segment becomes selected (the segmented control selectedSegmentIndex is set to that segment’s index). ● Momentary selection. When the user taps a segment, the segment does not become selected, but the segment appears selected while the user holds it. ArgumentMethodSelection NOmomentaryUnselected YESmomentarySelected 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 215 Segmented Control
  • 216. Tint The color of the segmented control. tintColor Segments The number of segments in the segmented control. Access: numberOfSegments. Segment Appearance and Behavior This group specifies the appearance and behavior for each of the segmented control segments. Segment The segment to configure. Choose a segment, and then configure the properties in this group. Title The title of the segment identified by Segment. Access: setTitle:forSegmentAtIndex:. Image The image of the segment identified by Segment. Access: setImage:forSegmentAtIndex:. Behavior Enabled Whether segment identified by Segment is enabled. ArgumentMethodSelection NOsetEnabled: forSegmentAtIndex:Unselected YESsetEnabled: forSegmentAtIndex:Selected Segmented Control Segmented Control Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 216
  • 217. Selected Whether segment identified by Segment is selected. Use selectedSegmentIndex to select a segment. Selection Unselected Selected Content Offset The offset from the segment origin at which to draw the content of the segment identified by Segment. Access: setContentOffset:forSegmentAtIndex:. Segmented Control Segmented Control Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 217
  • 218. Slider Attributes Inspector Reference Value Minimum The bottom of the range of values the slider can have. Access: minimumValue. Maximum The top of the range of values the slider can have. Access: maximumValue. Current The numeric value of the slider. Access: value. Images Min Image The image displayed on the minimum side of the slider. Access: minimumValueImage. Max Image The image displayed on the maximum side of the slider. Access: maximumValueImage. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 218 Slider
  • 219. Appearance Min Track Tint The color of the track on the minimum side of the slider. Access: minimumTrackTintColor. Max Track Tint The color of the track on the maximum side of the slider. Access: maximumTrackTintColor. Thumb Tint The color of the slider thumb. Access" thumbTintColor. Update Events Continuous Whether the slider continuously sends update events as the user moves the thumb. You can receive updated values on the slider by responding to the value changed event UIControlEventValueChanged. In continuous updates, the slider sends multiple value changed events as the user moves the thumb. In noncontinuous updates, the slider sends one value changed event when the user releases the thumb. ArgumentMethodSelection NOcontinuousUnselected YEScontinuousSelected Slider Slider Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 219
  • 220. Stepper Attributes Inspector Reference Value Minimum The minimum value of the stepper. Access: minimumValue. Maximum The maximum value of the stepper. Access: maximumValue. Current The value of the stepper. Access: value. Step The amount by which the stepper increments or decrements its value. Access: stepValue. Behavior Autorepeat Whether the stepper keeps incrementing or decrementing its value while either of its buttons is held down. ArgumentMethodSelection NOautorepeatUnselected 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 220 Stepper
  • 221. ArgumentMethodSelection YESautorepeatSelected Continuous Whether the stepper continuously sends update events as either of its buttons is held down. In continuous updates the stepper sends update events as the user holds the button. In noncontinuous updates the stepper sends one update event when the user releases the button. ArgumentMethodSelection NOcontinuousUnselected YEScontinuousSelected Wraps Whether the stepper wraps around the minimum and maximum values. ArgumentMethodSelection NOwrapsUnselected YESwrapsSelected Stepper Stepper Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 221
  • 222. Switch Attributes Inspector Reference Appearance and State State Whether the switch is on or off. ArgumentMethodSelection YESonOn NOonOff On Tint The color of the switch when it is on. Access: onTintColor. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 222 Switch
  • 223. Tab Bar Attributes Inspector Reference Appearance Tint The color of the tab bar. Access: tintColor. Image Tint The color for the image of tab bar items when selected at runtime. Access: selectedImageTintColor. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 223 Tab Bar
  • 224. Tab Bar Item Attributes Inspector Reference Appearance Badge The tab bar item badge. Access: badgeValue. Identifier The tab bar item icon. ArgumentMethodSelection Custom UITabBarSystemItemMoreinitWithTabBarSystemItem: tag:More UITabBarSystemItemFavoritesinitWithTabBarSystemItem: tag:Favorites UITabBarSystemItemFeaturedinitWithTabBarSystemItem: tag:Featured UITabBarSystemItemTopRatedinitWithTabBarSystemItem: tag:Top Rated UITabBarSystemItemRecentsinitWithTabBarSystemItem: tag:Recents UITabBarSystemItemContactsinitWithTabBarSystemItem: tag:Contacts UITabBarSystemItemHistoryinitWithTabBarSystemItem: tag:History UITabBarSystemItemBookmarksinitWithTabBarSystemItem: tag:Bookmarks UITabBarSystemItemSearchinitWithTabBarSystemItem: tag:Search UITabBarSystemItemDownloadsinitWithTabBarSystemItem: tag:Downloads UITabBarSystemItemMostRecentinitWithTabBarSystemItem: tag:Most Recent UITabBarSystemItemMostViewedinitWithTabBarSystemItem: tag:Most Viewed 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 224 Tab Bar Item
  • 225. Table View Attributes Inspector Reference Appearance Style The basic appearance of the table view. ArgumentMethodSelection UITableViewStylePlainstylePlain UITableViewStyleGroupedstyleGrouped Separator Separator Style The style for table view cells used as separators. ArgumentMethodSelection UITableViewCellSeparatorStyleNoneseparatorStyleNone UITableViewCellSeparatorStyleSingleLineseparatorStyleSingle Line UITableViewCellSeparatorStyleSingle- LineEtched separatorStyleSingle Line Etched Separator Color The color for table view cells used as separators. Access: separatorColor 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 225 Table View
  • 226. Behavior Selection The type of selection the table view allows. Access: allowsSelection allowsMultipleSelection CodeSelection table_view.allowsSelection = NONo Selection table_view.allowsSelection = YESSingle Selection table_view.allowsMultipleSelection = YESMultiple Selection Editing The type of selection the table view allows in editing mode. Access: allowsSelectionDuringEditing allowsMultipleSelectionDuringEditing CodeSelection table_view.allowsSelectionDuringEditing = NONo Selection During Editing table_view.allowsSelectionDuringEditing = YESSingle Selection During Editing table_view.allowsMultipleSelectionDuringEditing = YES Multiple Selection During Editing Show Selection on Touch This item appears to be nonoperational. Table Index Index Row Limit This item appears to be nonoperational. Table View Table View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 226
  • 227. Table View Cell Attributes Inspector Reference Style The Image property appears in this group only when Style is Basic, Right Detail, or Subtitle. Style The appearance and layout of the table view cell labels. For the Custom style, your custom subclass of UITableViewCell determines the appearance of the table view cell. Access: reuseIdentifier ArgumentMethodSelection Custom UITableViewCellStyleDefaultinitWithStyle: reuseIdentifier:Basic UITableViewCellStyleValue1initWithStyle: reuseIdentifier:Right Detail UITableViewCellStyleValue2initWithStyle: reuseIdentifier:Left Detail UITableViewCellStyleSubtitleinitWithStyle: reuseIdentifier:Subtitle Image The image for the table view cell content. Access: image Cell Reuse Identifier 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 227 Table View Cell
  • 228. Identifies the table view cell for cell reuse. Access: initWithStyle:reuseIdentifier:reuseIdentifier Appearance Selection Whether and how the table view cell indicates that it is selected. ArgumentMethodSelection UITableViewCellSelectionStyleNoneselectionStyleNone UITableViewCellSelectionStyleBlueselectionStyleBlue UITableViewCellSelectionStyleGrayselectionStyleGray Accessory The accessory view type for the table view cell in the Normal state. The three states of a table view cell are: Normal, Editing, and Delete Confirmation (Cell State Mask Constants). ArgumentMethodSelection UITableViewCellAccessoryNoneaccessoryTypeNone UITableViewCellAccessoryDisclosureIndicatoraccessoryTypeDisclosure Indicator UITableViewCellAccessoryDetail- DisclosureButton accessoryTypeDetail Disclosure UITableViewCellAccessoryCheckmarkaccessoryTypeCheckmark Editing Acc. The accessory view type of the table view cell in the Editing state. The three states of a table view cell are: Normal, Editing, and Delete Confirmation (Cell State Mask Constants). Table View Cell Table View Cell Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 228
  • 229. ArgumentMethodSelection UITableViewCellAccessoryNoneeditingAccessoryTypeNone UITableViewCellAccessoryDisclosure- Indicator editingAccessoryTypeDisclosure Indicator UITableViewCellAccessoryDetail- DisclosureButton editingAccessoryTypeDetail Disclosure UITableViewCellAccessoryCheckmarkeditingAccessoryTypeCheckmark Indentation and Behavior Indentation Level The table view cell indentation level. Access: indentationLevel Width The width in points of each level of indentation. Access: indentationWidth Indent While Editing Whether to indent the table view cell background when the table view cell is in the Editing state. ArgumentMethodSelection NOshouldIndentWhileEditingUnselected YESshouldIndentWhileEditingSelected Shows Re-order Controls Whether the table view cell shows the reordering control. ArgumentMethodSelection NOshowsReorderControlUnselected Table View Cell Table View Cell Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 229
  • 230. ArgumentMethodSelection YESshowsReorderControlSelected Table View Cell Table View Cell Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 230
  • 231. Text View Attributes Inspector Reference Text Text Text Type The type of the text view text. Selection Plain Attributed Text Type: Plain Use this group to configure the text view plain text. Text The text view plain text. Access: text Color The color of the text view plain text. Access: textColor Font The font of the text view plain text. Access: font 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 231 Text View
  • 232. Alignment The alignment of the text view plain text. ArgumentMethodSelection NSTextAlignmentLefttextAlignmentLeft NSTextAlignmentCentertextAlignmentCenter NSTextAlignmentCentertextAlignmentRight Text Type: Attributed Use this group set the characteristics of the selected text in Attributed Text. To set alignment and other layout characteristics of part of the attributed text in code, you need to create an attributed string with the desired characteristics and assign it to attributedText. Attributed Text Layout The alignment and other layout characteristics of the selected attributed text. Selection Left Center Right Justified Natural Text Color Background Color More Font The font of the selected attributed text. Attributed Text Text View Text View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 232
  • 233. The the text view attributed text. Access: attributedText Allows Editing Attributes Whether the user can change characteristics of the attributed text. ArgumentMethodSelection NOallowsEditingTextAttributesUnselected YESallowsEditingTextAttributesSelected Behavior Editable Whether the user can edit text view text. ArgumentMethodSelection NOeditableUnselected YESeditableSeleted Data Detection Detection Links Whether the text view detects hyperlinks in the text. Access: dataDetectorTypes CodeSelection text_view.dataDetectorTypes &= ~UIDataDetectorTypeLinkUnselected text_view.dataDetectorTypes |= UIDataDetectorTypeLinkSelected Addresses Text View Text View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 233
  • 234. Whether the text view detects addresses in the text. Access: dataDetectorTypes CodeSelection text_view.dataDetectorTypes &= ~UIDataDetectorTypeAddressUnselected text_view.dataDetectorTypes |= UIDataDetectorTypeAddressesSelected Phone Numbers Whether the view detects phone numbers in the text. Access: dataDetectorTypes CodeSelection text_view.dataDetectorTypes &= ~UIDataDetectorTypePhoneNumberUnselected text_view.dataDetectorTypes |= UIDataDetectorTypePhoneNumberSelected Events Whether the text view detects calendar events in the text. Access: dataDetectorTypes CodeSelection text_view.dataDetectorTypes &= ~UIDataDetectorTypeCalendarEventUnselected text_view.dataDetectorTypes |= UIDataDetectorTypeCalendarEventSelected Text Input and Keyboard Capitalization Whether and when the keyboard activates the Shift key while the user types text. ArgumentMethodSelection UITextAutocapitalizationTypeNoneautocapitalizationTypeNone Text View Text View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 234
  • 235. ArgumentMethodSelection UITextAutocapitalizationTypeWordsautocapitalizationTypeWords UITextAutocapitalizationTypeSentencesautocapitalizationTypeSentences UITextAutocapitalization- TypeAllCharacters autocapitalizationTypeAll Characters Correction Whether to auto-correct text the text user types. ArgumentMethodSelection UITextAutocorrectionTypeDefaultautocorrectionTypeDefault UITextAutocorrectionTypeNoautocorrectionTypeNo UITextAutocorrectionTypeYesautocorrectionTypeYes Keyboard The keyboard that appears on text input. ArgumentMethodSelection UIKeyboardTypeDefaultkeyboardTypeDefault UIKeyboardTypeASCIICapablekeyboardTypeASCII Capable UIKeyboardTypeNumbersAnd- Punctuation keyboardTypeNumbers and Punctuation UIKeyboardTypeURLautocorrectionTypeURL UIKeyboardTypeNumberPadkeyboardTypeNumber Pad UIKeyboardTypePhonePadkeyboardTypePhone Pad UIKeyboardTypeNamePhonePadkeyboardTypeName Phone Pad UIKeyboardTypeEmailAddresskeyboardTypeE-mail Address Appearance The keyboard to use for text input. Text View Text View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 235
  • 236. ArgumentMethodSelection UIKeyboardAppearanceDefaultkeyboardAppearanceDefault UIKeyboardAppearanceAlertkeyboardAppearanceAlert Return Key The type of the keyboard Return key. The type of the Return key specifies the Return key title. ArgumentMethodSelection UIReturnKeyDefaultreturnKeyTypeDefault UIReturnKeyGoreturnKeyTypeGo UIReturnKeyGooglereturnKeyTypeGoogle UIReturnKeyJoinreturnKeyTypeJoin UIReturnKeyNextreturnKeyTypeNext UIReturnKeyRoutereturnKeyTypeRoute UIReturnKeySearchreturnKeyTypeSearch UIReturnKeySendreturnKeyTypeSend UIReturnKeyYahooreturnKeyTypeYahoo UIReturnKeyDonereturnKeyTypeDone UIReturnKeyEmergencyCallreturnKeyTypeEmergency Call Auto-enable Return Key Whether the user can press the Return key after entering text. ArgumentMethodSelection NOenablesReturnKeyAutomaticallyUnselected YESenablesReturnKeyAutomaticallySelected Text View Text View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 236
  • 237. Secure Whether the text view hides entered text. ArgumentMethodSelection NOsecureTextEntryUnselected YESsecureTextEntrySelected Text View Text View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 237
  • 238. Toolbar Attributes Inspector Reference Appearance Style The basic appearance of the toolbar. ArgumentMethodSelection UIBarStyleDefaultbarStyleDefault UIBarStyleBlackbarStyleBlack Opaque UIBarStyleBlackTranslucentbarStyleBlack Translucent Tint The color of the toolbar. Access: tintColor. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 238 Toolbar
  • 239. View Attributes Inspector Reference Layout and Tagging Mode How the view presents its content when the view size changes. ArgumentMethodSelection UIViewContentModeScaleToFillcontentModeScale to Fill UIViewContentModeScaleAspectFitcontentModeAspect Fit UIViewContentModeScaleAspectFillcontentModeAspect Fill UIViewContentModeRedrawcontentModeRedraw UIViewContentModeCentercontentModeCenter UIViewContentModeTopcontentModeTop UIViewContentModeBottomcontentModeBottom UIViewContentModeLeftcontentModeLeft UIViewContentModeRightcontentModeRight UIViewContentModeTopLeftcontentModeTop Left UIViewContentModeTopRightcontentModeTop Right UIViewContentModeBottomLeftcontentModeBottom Left UIViewContentModeBottomRightcontentModeBottom Right Tag The view tag. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 239 View
  • 240. Access: tag. Events Interaction User Interaction Enabled Whether the view processes touch and keyboard events. ArgumentMethodSelection NOuserInteractionEnabledUnselected YESuserInteractionEnabledSelected Multiple Touch Whether the view processes multiple touch events. ArgumentMethodSelection NOmultipleTouchEnabledUnselected YESmultipleTouchEnabledSelected Appearance Alpha The view transparency. The range of values is from 0.0 and 1.0: ● 0.0 makes the view completely transparent. ● 1.0 makes the view completely opaque. Access: alpha. Background The view background color. View View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 240
  • 241. Access: backgroundColor. Drawing and Sizing Drawing Opaque Whether the drawing system treats the view as opaque. ArgumentMethodSelection NOopaqueUnselected YESopaqueSelected Hidden Whether the view is hidden. ArgumentMethodSelection NOhiddenUnselected YEShiddenSelected Clears Graphics Context Whether the view clears its bounds before drawing. ArgumentMethodSelection NOclearsContextBeforeDrawingUnselected YESclearsContextBeforeDrawingSelected Clip Subviews Whether subviews are clipped to the view bounds. If the view alpha value (alpha) is 1.0, drawing performance can be improved by indicating that the view is opaque. View View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 241
  • 242. ArgumentMethodSelection NOclipsToBoundsUnselected YESclipsToBoundsSelected Autoresize Subviews Whether the view resizes subviews when the view size changes. If the view alpha value (alpha) is 1.0, drawing performance can be improved by indicating that the view is opaque. ArgumentMethodSelection NOautoresizesSubviewsUnselected YESautoresizesSubviewsSelected Sizing Stretching The rectangle that identifies stretchable area of the view. The values for the rectangle specifiers (X, Y, Width, and Height) are in the range 0.0 to 1.0. For example, to make only half of the view stretchable, specify the rectangle (0.0, 0.0, 0.5, 1.0). Access: contentStretch. View View Attributes Inspector Reference 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 242
  • 243. Web View Attributes Inspector Data Detection and Sizing Scaling Scales Page to Fit Whether the view resizes the webpage to fit the view bounds. ArgumentMethodSelection NOautoresizesSubviewsUnselected YESautoresizesSubviewsSelected Detection Links Whether the view detects hyperlinks in the webpage. Access: dataDetectorTypes. CodeSelection web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypeLinkUnselected web_view.dataDetectorTypes |= UIDataDetectorTypeLinkSelected Addresses Whether the view detects addresses in the webpage. Access: dataDetectorTypes. 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 243 Web View
  • 244. CodeSelection web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypeAddressUnselected web_view.dataDetectorTypes |= UIDataDetectorTypeAddressesSelected Phone Numbers Whether the view detects phone numbers in the webpage. CodeSelection web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypePhoneNumberUnselected web_view.dataDetectorTypes |= UIDataDetectorTypePhoneNumberSelected Events Whether the view detects calendar events in the webpage. CodeSelection web_view.dataDetectorTypes &amp;= ~UIDataDetectorTypeCalendarEventUnselected web_view.dataDetectorTypes |= UIDataDetectorTypeCalendarEventSelected Web View Web View Attributes Inspector 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 244
  • 245. This table describes the changes to UIKit User Interface Catalog. NotesDate New document that describes the views and controls in UIKit, drawing from the human interface guidelines for more depth. 2013-06-10 2013-06-10 | Copyright © 2013 Apple Inc. All Rights Reserved. Apple Confidential Information. 245 Document Revision History
  • 246. Apple Inc. Copyright © 2013 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apple’s copyright notice. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, Cocoa, GarageBand, iPad, iPhone, iTunes, Numbers, Pages, Safari, and Xcode are trademarks of Apple Inc., registered in the U.S. and other countries. Genius is a service mark of Apple Inc., registered in the U.S. and other countries. X Window System is a trademark of the Massachusetts Institute of Technology. iOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used under license. Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED “AS IS,” AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.