@@ -9,7 +9,6 @@ import UIKit
9
9
import ZLImageEditor
10
10
11
11
class ViewController : UIViewController {
12
-
13
12
var editImageToolView : UIView !
14
13
15
14
var editImageDrawToolSwitch : UISwitch !
@@ -44,8 +43,8 @@ class ViewController: UIViewController {
44
43
}
45
44
46
45
func setupUI( ) {
47
- self . title = " Main "
48
- self . view. backgroundColor = . white
46
+ title = " Main "
47
+ view. backgroundColor = . white
49
48
50
49
func createLabel( _ title: String ) -> UILabel {
51
50
let label = UILabel ( )
@@ -57,154 +56,154 @@ class ViewController: UIViewController {
57
56
58
57
let spacing : CGFloat = 20
59
58
// Container
60
- self . editImageToolView = UIView ( )
61
- self . view. addSubview ( self . editImageToolView)
62
- self . editImageToolView. snp. makeConstraints { ( make) in
59
+ editImageToolView = UIView ( )
60
+ view. addSubview ( editImageToolView)
61
+ editImageToolView. snp. makeConstraints { make in
63
62
make. top. equalTo ( self . view. snp. topMargin) . offset ( 5 )
64
63
make. left. equalTo ( self . view) . offset ( 20 )
65
64
make. right. equalTo ( self . view) . offset ( - 20 )
66
65
}
67
66
68
67
let drawToolLabel = createLabel ( " Draw " )
69
- self . editImageToolView. addSubview ( drawToolLabel)
70
- drawToolLabel. snp. makeConstraints { ( make) in
68
+ editImageToolView. addSubview ( drawToolLabel)
69
+ drawToolLabel. snp. makeConstraints { make in
71
70
make. top. equalTo ( self . editImageToolView) . offset ( spacing)
72
71
make. left. equalTo ( self . editImageToolView)
73
72
}
74
73
75
- self . editImageDrawToolSwitch = UISwitch ( )
76
- self . editImageDrawToolSwitch. isOn = config. tools. contains ( . draw)
77
- self . editImageDrawToolSwitch. addTarget ( self , action: #selector( drawToolChanged) , for: . valueChanged)
78
- self . editImageToolView. addSubview ( self . editImageDrawToolSwitch)
79
- self . editImageDrawToolSwitch. snp. makeConstraints { ( make) in
74
+ editImageDrawToolSwitch = UISwitch ( )
75
+ editImageDrawToolSwitch. isOn = config. tools. contains ( . draw)
76
+ editImageDrawToolSwitch. addTarget ( self , action: #selector( drawToolChanged) , for: . valueChanged)
77
+ editImageToolView. addSubview ( editImageDrawToolSwitch)
78
+ editImageDrawToolSwitch. snp. makeConstraints { make in
80
79
make. left. equalTo ( drawToolLabel. snp. right) . offset ( spacing)
81
80
make. centerY. equalTo ( drawToolLabel)
82
81
}
83
82
84
83
let cropToolLabel = createLabel ( " Crop " )
85
- self . editImageToolView. addSubview ( cropToolLabel)
86
- cropToolLabel. snp. makeConstraints { ( make) in
84
+ editImageToolView. addSubview ( cropToolLabel)
85
+ cropToolLabel. snp. makeConstraints { make in
87
86
make. centerY. equalTo ( drawToolLabel)
88
87
make. left. equalTo ( self . editImageToolView. snp. centerX)
89
88
}
90
89
91
- self . editImageClipToolSwitch = UISwitch ( )
92
- self . editImageClipToolSwitch. isOn = config. tools. contains ( . clip)
93
- self . editImageClipToolSwitch. addTarget ( self , action: #selector( clipToolChanged) , for: . valueChanged)
94
- self . editImageToolView. addSubview ( self . editImageClipToolSwitch)
95
- self . editImageClipToolSwitch. snp. makeConstraints { ( make) in
90
+ editImageClipToolSwitch = UISwitch ( )
91
+ editImageClipToolSwitch. isOn = config. tools. contains ( . clip)
92
+ editImageClipToolSwitch. addTarget ( self , action: #selector( clipToolChanged) , for: . valueChanged)
93
+ editImageToolView. addSubview ( editImageClipToolSwitch)
94
+ editImageClipToolSwitch. snp. makeConstraints { make in
96
95
make. left. equalTo ( cropToolLabel. snp. right) . offset ( spacing)
97
96
make. centerY. equalTo ( cropToolLabel)
98
97
}
99
98
100
99
let imageStickerToolLabel = createLabel ( " Image sticker " )
101
- self . editImageToolView. addSubview ( imageStickerToolLabel)
102
- imageStickerToolLabel. snp. makeConstraints { ( make) in
100
+ editImageToolView. addSubview ( imageStickerToolLabel)
101
+ imageStickerToolLabel. snp. makeConstraints { make in
103
102
make. top. equalTo ( drawToolLabel. snp. bottom) . offset ( spacing)
104
103
make. left. equalTo ( self . editImageToolView)
105
104
}
106
105
107
- self . editImageImageStickerToolSwitch = UISwitch ( )
108
- self . editImageImageStickerToolSwitch. isOn = config. tools. contains ( . imageSticker)
109
- self . editImageImageStickerToolSwitch. addTarget ( self , action: #selector( imageStickerToolChanged) , for: . valueChanged)
110
- self . editImageToolView. addSubview ( self . editImageImageStickerToolSwitch)
111
- self . editImageImageStickerToolSwitch. snp. makeConstraints { ( make) in
106
+ editImageImageStickerToolSwitch = UISwitch ( )
107
+ editImageImageStickerToolSwitch. isOn = config. tools. contains ( . imageSticker)
108
+ editImageImageStickerToolSwitch. addTarget ( self , action: #selector( imageStickerToolChanged) , for: . valueChanged)
109
+ editImageToolView. addSubview ( editImageImageStickerToolSwitch)
110
+ editImageImageStickerToolSwitch. snp. makeConstraints { make in
112
111
make. left. equalTo ( imageStickerToolLabel. snp. right) . offset ( spacing)
113
112
make. centerY. equalTo ( imageStickerToolLabel)
114
113
}
115
114
116
115
let textStickerToolLabel = createLabel ( " Text sticker " )
117
- self . editImageToolView. addSubview ( textStickerToolLabel)
118
- textStickerToolLabel. snp. makeConstraints { ( make) in
116
+ editImageToolView. addSubview ( textStickerToolLabel)
117
+ textStickerToolLabel. snp. makeConstraints { make in
119
118
make. centerY. equalTo ( imageStickerToolLabel)
120
119
make. left. equalTo ( self . editImageToolView. snp. centerX)
121
120
}
122
121
123
- self . editImageTextStickerToolSwitch = UISwitch ( )
124
- self . editImageTextStickerToolSwitch. isOn = config. tools. contains ( . textSticker)
125
- self . editImageTextStickerToolSwitch. addTarget ( self , action: #selector( textStickerToolChanged) , for: . valueChanged)
126
- self . editImageToolView. addSubview ( self . editImageTextStickerToolSwitch)
127
- self . editImageTextStickerToolSwitch. snp. makeConstraints { ( make) in
122
+ editImageTextStickerToolSwitch = UISwitch ( )
123
+ editImageTextStickerToolSwitch. isOn = config. tools. contains ( . textSticker)
124
+ editImageTextStickerToolSwitch. addTarget ( self , action: #selector( textStickerToolChanged) , for: . valueChanged)
125
+ editImageToolView. addSubview ( editImageTextStickerToolSwitch)
126
+ editImageTextStickerToolSwitch. snp. makeConstraints { make in
128
127
make. left. equalTo ( textStickerToolLabel. snp. right) . offset ( spacing)
129
128
make. centerY. equalTo ( textStickerToolLabel)
130
129
}
131
130
132
131
let mosaicToolLabel = createLabel ( " Mosaic " )
133
- self . editImageToolView. addSubview ( mosaicToolLabel)
134
- mosaicToolLabel. snp. makeConstraints { ( make) in
132
+ editImageToolView. addSubview ( mosaicToolLabel)
133
+ mosaicToolLabel. snp. makeConstraints { make in
135
134
make. top. equalTo ( imageStickerToolLabel. snp. bottom) . offset ( spacing)
136
135
make. left. equalTo ( self . editImageToolView)
137
136
}
138
137
139
- self . editImageMosaicToolSwitch = UISwitch ( )
140
- self . editImageMosaicToolSwitch. isOn = config. tools. contains ( . mosaic)
141
- self . editImageMosaicToolSwitch. addTarget ( self , action: #selector( mosaicToolChanged) , for: . valueChanged)
142
- self . editImageToolView. addSubview ( self . editImageMosaicToolSwitch)
143
- self . editImageMosaicToolSwitch. snp. makeConstraints { ( make) in
138
+ editImageMosaicToolSwitch = UISwitch ( )
139
+ editImageMosaicToolSwitch. isOn = config. tools. contains ( . mosaic)
140
+ editImageMosaicToolSwitch. addTarget ( self , action: #selector( mosaicToolChanged) , for: . valueChanged)
141
+ editImageToolView. addSubview ( editImageMosaicToolSwitch)
142
+ editImageMosaicToolSwitch. snp. makeConstraints { make in
144
143
make. left. equalTo ( mosaicToolLabel. snp. right) . offset ( spacing)
145
144
make. centerY. equalTo ( mosaicToolLabel)
146
145
}
147
146
148
147
let filterToolLabel = createLabel ( " Filter " )
149
- self . editImageToolView. addSubview ( filterToolLabel)
150
- filterToolLabel. snp. makeConstraints { ( make) in
148
+ editImageToolView. addSubview ( filterToolLabel)
149
+ filterToolLabel. snp. makeConstraints { make in
151
150
make. centerY. equalTo ( mosaicToolLabel)
152
151
make. left. equalTo ( self . editImageToolView. snp. centerX)
153
152
}
154
153
155
- self . editImageFilterToolSwitch = UISwitch ( )
156
- self . editImageFilterToolSwitch. isOn = config. tools. contains ( . filter)
157
- self . editImageFilterToolSwitch. addTarget ( self , action: #selector( filterToolChanged) , for: . valueChanged)
158
- self . editImageToolView. addSubview ( self . editImageFilterToolSwitch)
159
- self . editImageFilterToolSwitch. snp. makeConstraints { ( make) in
154
+ editImageFilterToolSwitch = UISwitch ( )
155
+ editImageFilterToolSwitch. isOn = config. tools. contains ( . filter)
156
+ editImageFilterToolSwitch. addTarget ( self , action: #selector( filterToolChanged) , for: . valueChanged)
157
+ editImageToolView. addSubview ( editImageFilterToolSwitch)
158
+ editImageFilterToolSwitch. snp. makeConstraints { make in
160
159
make. left. equalTo ( filterToolLabel. snp. right) . offset ( spacing)
161
160
make. centerY. equalTo ( filterToolLabel)
162
161
}
163
162
164
163
let adjustToolLabel = createLabel ( " Adjust " )
165
- self . editImageToolView. addSubview ( adjustToolLabel)
166
- adjustToolLabel. snp. makeConstraints { ( make) in
164
+ editImageToolView. addSubview ( adjustToolLabel)
165
+ adjustToolLabel. snp. makeConstraints { make in
167
166
make. top. equalTo ( mosaicToolLabel. snp. bottom) . offset ( spacing)
168
167
make. left. equalTo ( self . editImageToolView)
169
168
}
170
169
171
- self . editImageAdjustToolSwitch = UISwitch ( )
172
- self . editImageAdjustToolSwitch. isOn = config. tools. contains ( . adjust)
173
- self . editImageAdjustToolSwitch. addTarget ( self , action: #selector( adjustToolChanged) , for: . valueChanged)
174
- self . editImageToolView. addSubview ( self . editImageAdjustToolSwitch)
175
- self . editImageAdjustToolSwitch. snp. makeConstraints { ( make) in
170
+ editImageAdjustToolSwitch = UISwitch ( )
171
+ editImageAdjustToolSwitch. isOn = config. tools. contains ( . adjust)
172
+ editImageAdjustToolSwitch. addTarget ( self , action: #selector( adjustToolChanged) , for: . valueChanged)
173
+ editImageToolView. addSubview ( editImageAdjustToolSwitch)
174
+ editImageAdjustToolSwitch. snp. makeConstraints { make in
176
175
make. left. equalTo ( adjustToolLabel. snp. right) . offset ( spacing)
177
176
make. centerY. equalTo ( adjustToolLabel)
178
177
make. bottom. equalTo ( self . editImageToolView)
179
178
}
180
179
181
- self . pickImageBtn = UIButton ( type: . custom)
182
- self . pickImageBtn. backgroundColor = . black
183
- self . pickImageBtn. layer. cornerRadius = 5
184
- self . pickImageBtn. layer. masksToBounds = true
185
- self . pickImageBtn. titleLabel? . font = UIFont . systemFont ( ofSize: 14 )
186
- self . pickImageBtn. setTitle ( " Pick an image " , for: . normal)
187
- self . pickImageBtn. addTarget ( self , action: #selector( pickImage) , for: . touchUpInside)
188
- self . view. addSubview ( self . pickImageBtn)
189
- self . pickImageBtn. snp. makeConstraints { ( make) in
180
+ pickImageBtn = UIButton ( type: . custom)
181
+ pickImageBtn. backgroundColor = . black
182
+ pickImageBtn. layer. cornerRadius = 5
183
+ pickImageBtn. layer. masksToBounds = true
184
+ pickImageBtn. titleLabel? . font = UIFont . systemFont ( ofSize: 14 )
185
+ pickImageBtn. setTitle ( " Pick an image " , for: . normal)
186
+ pickImageBtn. addTarget ( self , action: #selector( pickImage) , for: . touchUpInside)
187
+ view. addSubview ( pickImageBtn)
188
+ pickImageBtn. snp. makeConstraints { make in
190
189
make. top. equalTo ( self . editImageToolView. snp. bottom) . offset ( spacing)
191
190
make. left. equalTo ( self . editImageToolView)
192
191
}
193
192
194
- self . resultImageView = UIImageView ( )
195
- self . resultImageView. contentMode = . scaleAspectFit
196
- self . resultImageView. clipsToBounds = true
197
- self . view. addSubview ( self . resultImageView)
198
- self . resultImageView. snp. makeConstraints { ( make) in
193
+ resultImageView = UIImageView ( )
194
+ resultImageView. contentMode = . scaleAspectFit
195
+ resultImageView. clipsToBounds = true
196
+ view. addSubview ( resultImageView)
197
+ resultImageView. snp. makeConstraints { make in
199
198
make. top. equalTo ( self . pickImageBtn. snp. bottom) . offset ( spacing)
200
199
make. left. right. equalTo ( self . view)
201
200
make. bottom. equalTo ( self . view. snp. bottomMargin)
202
201
}
203
202
204
203
let control = UIControl ( )
205
204
control. addTarget ( self , action: #selector( continueEditImage) , for: . touchUpInside)
206
- self . view. addSubview ( control)
207
- control. snp. makeConstraints { ( make) in
205
+ view. addSubview ( control)
206
+ control. snp. makeConstraints { make in
208
207
make. edges. equalTo ( self . resultImageView)
209
208
}
210
209
}
@@ -233,7 +232,7 @@ class ViewController: UIViewController {
233
232
picker. delegate = self
234
233
picker. sourceType = . photoLibrary
235
234
picker. mediaTypes = [ " public.image " ]
236
- self . showDetailViewController ( picker, sender: nil )
235
+ showDetailViewController ( picker, sender: nil )
237
236
}
238
237
239
238
@objc func drawToolChanged( ) {
@@ -293,34 +292,31 @@ class ViewController: UIViewController {
293
292
}
294
293
295
294
@objc func continueEditImage( ) {
296
- guard let oi = self . originalImage else {
295
+ guard let oi = originalImage else {
297
296
return
298
297
}
299
- self . editImage ( oi, editModel: self . resultImageEditModel)
298
+
299
+ editImage ( oi, editModel: resultImageEditModel)
300
300
}
301
301
302
302
func editImage( _ image: UIImage , editModel: ZLEditImageModel ? ) {
303
- ZLEditImageViewController . showEditImageVC ( parentVC: self , image: image, editModel: editModel) { [ weak self] ( resImage, editModel) in
303
+ ZLEditImageViewController . showEditImageVC ( parentVC: self , image: image, editModel: editModel) { [ weak self] resImage, editModel in
304
304
self ? . resultImageView. image = resImage
305
305
self ? . resultImageEditModel = editModel
306
306
}
307
307
}
308
-
309
308
}
310
309
311
-
312
310
extension ViewController : UIImagePickerControllerDelegate , UINavigationControllerDelegate {
313
-
314
311
func imagePickerControllerDidCancel( _ picker: UIImagePickerController ) {
315
312
picker. dismiss ( animated: true , completion: nil )
316
313
}
317
314
318
- func imagePickerController( _ picker: UIImagePickerController , didFinishPickingMediaWithInfo info: [ UIImagePickerController . InfoKey : Any ] ) {
315
+ func imagePickerController( _ picker: UIImagePickerController , didFinishPickingMediaWithInfo info: [ UIImagePickerController . InfoKey : Any ] ) {
319
316
picker. dismiss ( animated: true ) {
320
317
guard let image = info [ . originalImage] as? UIImage else { return }
321
318
self . originalImage = image
322
319
self . editImage ( image, editModel: nil )
323
320
}
324
321
}
325
-
326
322
}
0 commit comments