iOS Developer: Notes for Professionals

GoalKicker.com (CC BY-SA)
Page 1 sur 893Lecteur de document UniversityLib

iOS Developer: Notes for Professionals

Programming, iOS Development · notes

Browse all programmation documents

iOS Developer

Notes for Professionals

iOS®

Developer

Notes for Professionals

800+ pages

of professional hints and tricks

GoalKicker.com

Free Programming Books

Disclaimer

This is an unocial free book created for educational purposes and is

not aliated with ocial iOS® Developer group(s) or company(s).

All trademarks and registered trademarks are

the property of their respective owners

Contents

About

...................................................................................................................................................................................

1

Chapter 1: Getting started with iOS Development

Section 1.1: Creating a default Single View Application

Section 1.2: Hello World

Section 1.3: Xcode Interface

Section 1.4: Create your first program in Swift 3

.................................................................................................................................................

.......................................................................................................................................

......................................................................................................

......................................................................................

2

.............................................................................................

Chapter 2: UILabel

......................................................................................................................................................

22

......................................................................................................................................

.....................................................................................................................................

....................................................................................................................................................

................................................................................................................................................

..................................................................................................................................

..................................................................................................................................................

........................................................................................................................................

Section 2.1: Create a UILabel

Section 2.2: Number of Lines

Section 2.3: Set Font

Section 2.4: Text Color

Section 2.5: Background Color

Section 2.6: Size to fit

Section 2.7: Text alignment

Section 2.8: Calculate Content Bounds (for i.e. dynamic cell heights)

Section 2.9: Label Attributed Text

Section 2.10: Clickable Label

Section 2.11: Variable height using constraints

Section 2.12: LineBreakMode

Section 2.13: Add shadows to text

Section 2.14: Changing Text in an Existing Label

Section 2.15: Auto-size label to fit text

Section 2.16: Get UILabel's size strictly based on its text and font

Section 2.17: Highlighted and Highlighted Text Color

Section 2.18: Justify Text

Section 2.19: Dynamic label frame from unknown text length

..............................................................................................................................

......................................................................................................................................

.........................................................................................................

......................................................................................................................................

.............................................................................................................................

.....................................................................................................

.......................................................................................................................

.........................................................................

..............................................................................................

............................................................................................................................................

...............................................................................

..................................................................

30

Chapter 3: UILabel text underlining

..................................................................................................................

47

Section 3.1: Underlining a text in a UILabel using Objective C

Section 3.2: Underlining a text in UILabel using Swift

................................................................................

47

..............................................................................................

47

Chapter 4: attributedText in UILabel

...............................................................................................................

48

Section 4.1: HTML text in UILabel

Section 4.2: Set dierent property to text in single UILabel

...............................................................................................................................

48

...................................................................................

48

Chapter 5: UIButton

...................................................................................................................................................

50

................................................................................................................................

...........................................................................................................

.............................................................................................................................................

................................................................................................................................................

Section 5.1: Creating a UIButton

Section 5.2: Attaching a Method to a Button

Section 5.3: Setting Font

Section 5.4: Set Image

Section 5.5: Get UIButton's size strictly based on its text and font

Section 5.6: Disabling a UIButton

Section 5.7: Set title

Section 5.8: Set title color

Section 5.9: Horizontally aligning contents

Section 5.10: Getting the title label

Section 5.11: Adding an action to an UIButton via Code (programmatically)

...............................................................................................................................

.....................................................................................................................................................

...........................................................................................................................................

..............................................................................................................

.............................................................................................................................

........................................................................

.......................................................

54

Chapter 6: UIDatePicker

..........................................................................................................................................

55

Section 6.1: Create a Date Picker

Section 6.2: Setting Minimum-Maximum Date

...............................................................................................................................

55

.........................................................................................................

55

2

6

11

17

22

24

25

26

27

Advertisement

27

30

32

38

39

39

41

41

42

43

44

44

45

50

50

51

51

51

52

52

52

53

53

Section 6.3: Modes

Section 6.4: Setting minute interval

Section 6.5: Count Down Duration

Chapter 7: UILocalNotification

.......................................................................................................................................................

55

...........................................................................................................................

55

.............................................................................................................................

............................................................................................................................

Section 7.1: Scheduling a local notification

Section 7.2: Presenting a local notification immediately

Section 7.3: Managing local notifications using UUID

Section 7.4: Registering for local notifications

Section 7.5: what's new in UILocalNotification with iOS10

Section 7.6: Responding to received local notification

Section 7.7: Register and Schedule Local Notification in Swift 3.0 (iOS 10)

...............................................................................................................

........................................................................................

.............................................................................................

.........................................................................................................

.......................................................................................

............................................................................................

...........................................................

62

Chapter 8: UIImage

....................................................................................................................................................

64

Section 8.1: Creating UIImage

Section 8.2: Comparing Images

Section 8.3: Gradient Image with Colors

Section 8.4: Convert UIImage to/from base64 encoding

Section 8.5: Take a Snapshot of a UIView

Section 8.6: Change UIImage Color

Section 8.7: Apply UIColor to UIImage

Section 8.8: Creating and Initializing Image Objects with file contents

Section 8.9: Resizable image with caps

Section 8.10: Gradient Background Layer for Bounds

Chapter 9: Convert NSAttributedString to UIImage

Section 9.1: NSAttributedString to UIImage Conversion

....................................................................................................................................

.................................................................................................................................

...................................................................................................................

.......................................................................................

................................................................................................................

...........................................................................................................................

67

......................................................................................................................

67

....................................................................................................................

.................................................................

68

............................................................................................

.................................................................................

..........................................................................................

Chapter 10: UIImagePickerController

...............................................................................................................

71

Section 10.1: Generic usage of UIImagePickerController

.........................................................................................

71

Chapter 11: UIImageView

.........................................................................................................................................

73

Section 11.1: UIImage masked with Label

Section 11.2: Making an image into a circle or rounded

Section 11.3: How the Mode property aects an image

Section 11.4: Animating a UIImageView

Section 11.5: Create a UIImageView

Section 11.6: Change color of an image

Section 11.7: Assigning an image to a UIImageView

..................................................................................................................

73

..........................................................................................

73

..........................................................................................

74

.....................................................................................................................

...........................................................................................................................

....................................................................................................................

................................................................................................

Chapter 12: Resizing UIImage

...............................................................................................................................

83

Section 12.1: Resize any image by size & quality

......................................................................................................

83

Chapter 13: Cut a UIImage into a circle

...........................................................................................................

84

................................................................................................

84

...................................................................................................................................

.........................................................................................................................................

.......................................................................................................................................

..........................................................................................................................................

......................................................................................................................................

Section 13.1: Cut a image into a circle - Objective C

Section 13.2: SWIFT 3 Example

Chapter 14: UITableView

Section 14.1: Self-Sizing Cells

Section 14.2: Custom Cells

Section 14.3: Separator Lines

Section 14.4: Delegate and Datasource

Section 14.5: Creating a UITableView

Section 14.6: Swipe to Delete Rows

Section 14.7: Expanding & Collapsing UITableViewCells

....................................................................................................................

........................................................................................................................

.........................................................................................................................

Advertisement

102

.......................................................................................

105

Chapter 15: UITableViewController

.................................................................................................................

108

Section 15.1: TableView with dynamic properties with tableviewCellStyle basic

................................................

108

56

57

57

57

58

59

60

62

64

65

66

66

67

68

69

70

70

80

81

82

82

85

87

87

87

90

92

98

Section 15.2: TableView with Custom Cell

Chapter 16: UIRefreshControl TableView

Section 16.1: Set up refreshControl on tableView:

Section 16.2: Objective-C Example

...............................................................................................................

109

.....................................................................................................

111

..................................................................................................

111

..........................................................................................................................

111

Chapter 17: UITableViewCell

...............................................................................................................................

113

Section 17.1: Xib file of UITableViewCell

...................................................................................................................

113

Chapter 18: Custom methods of selection of UITableViewCells

Section 18.1: Distinction between single and double selection on row

Chapter 19: Custom methods of selection of UITableViewCells

Section 19.1: Distinction between single and double selection on row

.......................................................

114

.................................................................

.......................................................

.................................................................

114

115

115

Chapter 20: UIView

..................................................................................................................................................

116

......................................................................................................................

Section 20.1: Make the view rounded

Section 20.2: Using IBInspectable and IBDesignable

Section 20.3: Taking a snapshot

Section 20.4: Create a UIView

Section 20.5: Shake a View

Section 20.6: Utilizing Intrinsic Content Size

Section 20.7: Programmatically manage UIView insertion and deletion into and from another UIView

......................................................................................................................................

..................................................................................................................................

..............................................................................................................................

...........................................................................................................

............................................................................................

116

118

121

121

121

122

.............................................................................................................................................................................

124

Section 20.8: Create UIView using Autolayout

Section 20.9: Animating a UIView

Section 20.10: UIView extension for size and frame attributes

.......................................................................................................

............................................................................................................................

............................................................................

127

Chapter 21: Snapshot of UIView

Section 21.1: Getting the Snapshot

Section 21.2: Snapshot with subview with other markup and text

........................................................................................................................

...........................................................................................................................

.......................................................................

129

Chapter 22: UIAlertController

.............................................................................................................................

131

Section 22.1: AlertViews with UIAlertController

Section 22.2: Action Sheets with UIAlertController

Section 22.3: Adding Text Field in UIAlertController like a prompt Box

Section 22.4: Highlighting an action button

Section 22.5: Displaying and handling alerts

......................................................................................................

................................................................................................

..............................................................

135

...........................................................................................................

.........................................................................................................

Chapter 23: UIColor

.................................................................................................................................................

141

...............................................................................................................................

Section 23.1: Creating a UIColor

Section 23.2: Creating a UIColor from hexadecimal number or string

Section 23.3: Color with Alpha component

Section 23.4: Undocumented Methods

Section 23.5: UIColor from an image pattern

Section 23.6: Lighter and Darker Shade of a given UIColor

Section 23.7: Make user defined attributes apply the CGColor datatype

...............................................................

.............................................................................................................

...................................................................................................................

Advertisement

........................................................................................................

.................................................................................

...........................................................

148

Chapter 24: UITextView

........................................................................................................................................

149

...............................................................................................................................

........................................................................................................................................

Section 24.1: Set attributed text

Section 24.2: Change font

Section 24.3: Auto Detect Links, Addresses, Dates, and more

Section 24.4: Change text

Section 24.5: Change text alignment

Section 24.6: UITextViewDelegate methods

Section 24.7: Change text color

Section 24.8: Remove extra paddings to fit to a precisely measured text

Section 24.9: Getting and Setting the Cursor Postition

.........................................................................................................................................

......................................................................................................................

..........................................................................................................

...............................................................................................................................

.........................................................

151

.........................................................................................

151

.............................................................................

125

127

129

129

131

132

135

136

141

142

144

145

146

147

149

149

149

150

150

150

151

Section 24.10: UITextView with HTML text

Section 24.11: Check to see if empty or nil

..............................................................................................................

153

..............................................................................................................

153

Chapter 25: UITextField Delegate

....................................................................................................................

154

Section 25.1: Actions when a user has started/ended interacting with a textfield

Section 25.2: UITextField - Restrict textfield to certain characters

......................................................................

155

.............................................

154

Chapter 26: UINavigationController

...............................................................................................................

156

Section 26.1: Embed a view controller in a navigation controller programmatically

Section 26.2: Popping in a Navigation Controller

Section 26.3: Purpose

Section 26.4: Pushing a view controller onto the navigation stack

Section 26.5: Creating a NavigationController

.....................................................................

.......................................................................................................

................................................................................................................................................

..................................................................................................

........................................

156

Chapter 27: UIGestureRecognizer

Section 27.1: UITapGestureRecognizer

Section 27.2: UITapGestureRecognizer (Double Tap)

Section 27.3: Adding a Gesture recognizer in the Interface Builder

Section 27.4: UILongPressGestureRecognizer

Section 27.5: UISwipeGestureRecognizer

Section 27.6: UIPinchGestureRecognizer

Section 27.7: UIRotationGestureRecognizer

....................................................................................................................

...................................................................................................................

..........................................................................................

....................................................................

159

.......................................................................................................

...............................................................................................................

................................................................................................................

...........................................................................................................

Chapter 28: UIBarButtonItem

............................................................................................................................

164

Section 28.1: Creating a UIBarButtonItem in the Interface Builder

Section 28.2: Creating a UIBarButtonItem

Section 28.3: Bar Button Item Original Image with no Tint Color

.............................................................................................................

........................................................................

......................................................................

164

Chapter 29: UIScrollView

.......................................................................................................................................

168

....................................................................................

........................................................................................................................

Section 29.1: Scrolling content with Auto Layout enabled

Section 29.2: Create a UIScrollView

Section 29.3: ScrollView with AutoLayout

Section 29.4: Detecting when UIScrollView finished scrolling with delegate methods

Section 29.5: Enable/Disable Scrolling

Section 29.6: Zoom In/Out UIImageView

Section 29.7: Scroll View Content Size

Section 29.8: Restrict scrolling direction

...................................................................................................................

...............................................................................................................

.....................................................................................................................

.................................................................................................................

...............................................................................................................

......................................

176

156

156

157

157

158

158

159

160

161

Advertisement

162

163

167

167

168

171

171

176

177

178

178

Chapter 30: UIStackView

......................................................................................................................................

179

Section 30.1: Center Buttons with UIStackview

Section 30.2: Create a horizontal stack view programmatically

Section 30.3: Create a vertical stack view programmatically

.........................................................................

183

..............................................................................

184

.......................................................................................................

179

Chapter 31: Dynamically updating a UIStackView

..................................................................................

185

Section 31.1: Connect the UISwitch to an action we can animate switching between a horizontal or vertical

layout of the image views

................................................................................................................................

185

Chapter 32: UIScrollView with StackView child

.........................................................................................

186

Section 32.1: A complex StackView inside Scrollview Example

Section 32.2: Preventing ambiguous layout

Section 32.3: Scrolling to content inside nested StackViews

...........................................................................................................

................................................................................

187

188

.............................................................................

186

Chapter 33: UIScrollView AutoLayout

............................................................................................................

189

Section 33.1: ScrollableController

Section 33.2: UIScrollView dynamic content size through Storyboard

.............................................................................................................................

189

...............................................................

193

Chapter 34: UITextField

.........................................................................................................................................

195

Section 34.1: Get Keyboard Focus and Hide Keyboard

Section 34.2: Dismiss keyboard when user pushes the return button

........................................................................................

195

.................................................................

195

....................................................................................................................................

..............................................................................................................................

.........................................................................................................

Section 34.3: Hide blinking caret

Section 34.4: Input accessory view (toolbar)

Section 34.5: Moving scroll when UITextView becomes first responder

Section 34.6: KeyboardType

Section 34.7: Change placeholder color and font

Section 34.8: Replace keyboard with UIPickerView

Section 34.9: Create a UITextField

Section 34.10: Getting and Setting the Cursor Position

Section 34.11: Dismiss Keyboard

Section 34.12: Initialize text field

Section 34.13: Autocapitalization

Section 34.14: Set Alignment

...........................................................................................................................

.........................................................................................

..............................................................................................................................

...............................................................................................................................

..............................................................................................................................

....................................................................................................................................

.................................................................................................

...............................................................................................

.............................................................

197

Chapter 35: Custom UITextField

.......................................................................................................................

210

Section 35.1: Custom UITextField for Filtering Input Text

Section 35.2: Custom UITextField to Disallow All Actions like Copy, Paste, etc

......................................................................................

210

..................................................

210

Chapter 36: UIViewController

.............................................................................................................................

212

..........................................................................................................................................

Section 36.1: Subclassing

Section 36.2: Access the container view controller

Section 36.3: Set the view programmatically

Section 36.4: Instantiate from a Storyboard

Section 36.5: Create an instance

Section 36.6: Adding/removing a child view controller

................................................................................................

.........................................................................................................

..........................................................................................................

.............................................................................................................................

.........................................................................................

216

Chapter 37: UISwitch

...............................................................................................................................................

217

Section 37.1: Set Image for On/O state

Section 37.2: Set On / O

Section 37.3: Set Background Color

Section 37.4: Set Tint Color

Chapter 38: UICollectionView

.........................................................................................................................................

........................................................................................................................

.......................................................................................................................................

.............................................................................................................................

................................................................................................................

217

..................................................................................................................

.........................................................................................................

........................................................................................

Section 38.1: Create a UICollectionView

Section 38.2: UICollectionView - Datasource

Section 38.3: Basic Swift example of a Collection View

Section 38.4: Manage Multiple Collection view with DataSource and Flowlayout

Section 38.5: UICollectionViewDelegate setup and item selection

Section 38.6: Create a Coll...