-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathios-swift-uiimagepicker.html
More file actions
181 lines (152 loc) · 6.15 KB
/
ios-swift-uiimagepicker.html
File metadata and controls
181 lines (152 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>TopDownU Tutorials</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/2-col-portfolio.css" rel="stylesheet">
<link href="tutorials.css" rel="stylesheet">
</head>
<body>
<div class="header">
<h2 class="tutorialTitle">Accessing user photos using UIImagePickerView</h2>
<p class="tutorialDescription">in 7 simple steps</p>
<p class="moreTutorials"><a class="moreTutorialsLink" href="http://topdownu.com/tutorials">MORE TUTORIALS</a></p>
</div>
<div class="row">
<div class="row-white">
<div class="padding-box">
<h2 class="stepTitle">Pre-requisites</h2>
<p class="stepParagraph"><a href="ios-new-xcode.html">Create a new Xcode Project</a></p>
</div>
</div>
</div>
<div class="row">
<div class="row-gray">
<div class="padding-box">
<h2 class="stepTitle">Setup Storyboard</h2>
<p class="stepParagraph">Go to Main.Storyboard, add a UIImageView and UIButton onto your ViewController as shown in the animation below,</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 1 of 7</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-white">
<div class="padding-box">
<h2 class="stepTitle">Connect UI Elements to your View Controller</h2>
<p class="stepParagraph">Connect your UIImageView and UIButton to your ViewController as IBOutlets and Connect your UIButton to ViewController as an IBAction. As shown in the animation below,</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 2 of 7</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-gray">
<div class="padding-box">
<h2 class="stepTitle">Inherit UIImagePickerControllerDelegate and UINavigationControllerDelegate Classes</h2>
<p class="stepParagraph">Replace ViewController class with the following code below,</p>
</div>
<div class="codeSnippet">
<p class="code">
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 3 of 7</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-white">
<div class="padding-box">
<h2 class="stepTitle">Initialize UIImagePickerView</h2>
<p class="stepParagraph">Initialize Image Picker view and connect to delegate as shown below</p>
</div>
<div class="codeSnippet">
<p class="code">
let imagePicker = UIImagePickerController()<br/><br/>
override func viewDidLoad() {<br/>
super.viewDidLoad()<br/>
// Do any additional setup after loading the view, typically from a nib.<br/><br/>
self.imagePicker.delegate = self<br/>
}<br/>
</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 4 of 7</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-gray">
<div class="padding-box">
<h2 class="stepTitle">Setup Upload Tapped</h2>
<p class="stepParagraph">Modify upload tapped button</p>
</div>
<div class="codeSnippet">
<p class="code">
imagePicker.allowsEditing = false<br/>
imagePicker.sourceType = .photoLibrary<br/>
present(imagePicker, animated: true, completion: nil)<br/>
</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 5 of 7</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-white">
<div class="padding-box">
<h2 class="stepTitle">Setup Delegate Methods</h2>
<p class="stepParagraph">Paste the delegate methods below into your ViewController class.</p>
</div>
<div class="codeSnippet">
<p class="code">
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){<br/>
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{<br/>
self.imageView.contentMode = .scaleAspectFit<br/>
self.imageView.image = pickedImage<br/>
}<br/>
dismiss(animated: true, completion: nil)<br/>
}<br/><br/>
func imagePickerControllerDidCancel(_ picker: UIImagePickerController){<br/>
dismiss(animated: true, completion: nil)<br/>
}<br/>
</p>
</div>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 6 of 7</h6>
</div>
</div>
</div>
<div class="row">
<div class="row-gray">
<div class="padding-box">
<h2 class="stepTitle">Run and test</h2>
<p class="stepParagraph">Hit the play button, you should be able to upload an image and see it appear on the image view.</p>
</div>
<div class="padding-box">
<h6 class="stepNumber">Step 7 of 7</h6>
</div>
</div>
</div>
<!-- Footer -->
<footer class="py-5 bg-light">
<center>Copyright TopDownU 2017</center>
</footer>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/popper/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>