CNImagePickerController.m
14.8 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//
// CNCNTZImagePickerControllerViewController.m
// CNLiveNetAdd
//
// Created by 梁星国 on 2018/8/22.
// Copyright © 2018年 cnlive. All rights reserved.
//
#import "CNImagePickerController.h"
#import <CNLiveBaseKit/CNLiveBaseKit.h>
#import <QMUIKit/QMUIKit.h>
@interface CNImagePickerController ()
@end
@implementation CNImagePickerController
- (void)viewDidLoad {
[super viewDidLoad];
}
/**
配置
*/
- (void)configCNTZImagePicker{
// imagePickerVc.navigationBar.translucent = NO;
#pragma mark - 五类个性化设置,这些参数都可以不传,此时会走默认设置
// 1.设置目前已经选中的图片数组
self.allowTakePicture = NO; // 在内部显示拍照按钮
self.allowTakeVideo = NO;// 在内部拍摄按钮
self.videoMaximumDuration = 10; // 视频最大拍摄时间
[self setUiImagePickerControllerSettingBlock:^(UIImagePickerController *imagePickerController) {
imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;//拍摄分辨率
}];
// imagePickerVc.photoWidth = 1000;
// 2. Set the appearance
// 2. 在这里设置imagePickerVc的外观
// if (iOS7Later) {
// imagePickerVc.navigationBar.barTintColor = [UIColor greenColor];
// }
// imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor];
// imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor];
// imagePickerVc.navigationBar.translucent = NO;
self.iconThemeColor = RGBOF(0x00BBE06);// 主体颜色
self.showPhotoCannotSelectLayer = YES;//达到上限是否有浮层
self.cannotSelectLayerColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];//设置达到上限的浮层
self.photoDefImage = [UIImage imageNamedFromMyBundle:@"photo_cell_normal"];
self.photoSelImage = [UIImage qmui_imageWithColor:RGBOF(0x0BBE06) size:CGSizeMake(22, 22) cornerRadius:11];
self.photoOriginDefImage = [UIImage imageNamedFromMyBundle:@"photo_original_nor"];
// 3. Set allow picking video & photo & originalPhoto or not
// 3. 设置是否可以选择视频/图片/原图/gif(未开放)
self.allowPickingVideo = YES;// 显示视频
self.allowPickingImage = YES;// 显示图片
self.allowPickingOriginalPhoto = YES; //显示原图
self.allowPickingGif = NO;// 显示GIF
self.allowPickingMultipleVideo = YES; // 是否可以多选视频
// 4. 照片排列按修改时间升序
self.sortAscendingByModificationDate = YES;
// imagePickerVc.minImagesCount = 3;
// imagePickerVc.alwaysEnableDoneBtn = YES;
// imagePickerVc.minPhotoWidthSelectable = 3000;
// imagePickerVc.minPhotoHeightSelectable = 2000;
/// 5. Single selection mode, valid when maxImagesCount = 1
/// 5. 单选模式,maxImagesCount为1时才生效
self.showSelectBtn = NO;
self.allowCrop = NO;
self.needCircleCrop = NO;
// 设置横屏下的裁剪尺寸
// imagePickerVc.cropRectLandscape = CGRectMake((self.view.CNTZ_height - widthHeight) / 2, left, widthHeight, widthHeight);
/*
[imagePickerVc setCropViewSettingBlock:^(UIView *cropView) {
cropView.layer.borderColor = [UIColor redColor].CGColor;
cropView.layer.borderWidth = 2.0;
}];*/
//imagePickerVc.allowPreview = NO;
// 自定义导航栏上的返回按钮
/*
[imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
[leftButton setImage:[UIImage imageNamedFromMyBundle:@"back"] forState:UIControlStateNormal];
[leftButton setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 20)];
}];
imagePickerVc.delegate = self;
*/
self.statusBarStyle = UIStatusBarStyleDefault;//状态栏黑色
self.showSelectedIndex = YES; // 设置是否显示图片序号
self.naviBgColor = RGBOF(0xFFFFFF);//导航栏颜色
self.naviTitleColor = RGBOF(0x282828);//相册title
self.naviTitleFont = [UIFont fontWithName:@"PingFangSC-Medium" size:18];//title文字大小
[self setNavLeftBarButtonSettingBlock:^(UIButton *leftButton) {//设置返回按钮图标
[leftButton setImage:[UIImage imageNamedFromMyBundle:@"photo_back"] forState:UIControlStateNormal];//返回按钮图片
[leftButton setTitle:@"返回" forState:UIControlStateNormal];//设置文字大小
[leftButton setTitleColor:RGBOF(0x282828) forState:UIControlStateNormal];//设置文字颜色
leftButton.titleLabel.font = [UIFont systemFontOfSize:15];//设置文字大小
leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -7, 0, +7);//设置图片边缘
}];
self.barItemTextColor = RGBOF(0x282828);//设置barItem文字颜色
self.barItemTextFont = [UIFont systemFontOfSize:15];
// 设置首选语言 / Set preferred language
// imagePickerVc.preferredLanguage = @"zh-Hans";
// 设置languageBundle以使用其它语言 / Set languageBundle to use other language
// imagePickerVc.languageBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"CNTZ-ru" ofType:@"lproj"]];
/// 【自定义各页面/组件的样式】在界面初始化/组件setModel完成后调用,允许外界修改样式等
//相册
[self setPhotoPickerPageUIConfigBlock:^(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine) {
//底部栏
[bottomToolBar setBackgroundColor:RGBOF(0xFFFFFF)];
//预览
previewButton.titleLabel.font = [UIFont systemFontOfSize:16];
[previewButton setTitleColor:RGBOF(0xB3B3B3) forState:UIControlStateDisabled];//禁用
[previewButton setTitleColor:RGBOF(0x000000) forState:UIControlStateNormal];//默认
//原图按钮
[originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_normal"] forState:UIControlStateDisabled];//禁用
[originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_normal"] forState:UIControlStateNormal];//默认
[originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_select"] forState:UIControlStateSelected];//选中
originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16];
[originalPhotoButton setTitleColor:RGBOF(0xB3B3B3) forState:UIControlStateDisabled];
[originalPhotoButton setTitleColor:RGBOF(0x000000) forState:UIControlStateNormal];
//原图文字提示
originalPhotoLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:16];
originalPhotoLabel.textColor = RGBOF(0xB3B3B3);
originalPhotoLabel.hidden = YES;
//选中提示
numberImageView = [UIImageView new];
numberLabel = [UILabel new];
//完成按钮
doneButton.titleLabel.font = [UIFont systemFontOfSize:13];
[doneButton setTitle:@"完成" forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBAOF(0xFFFFFF, 0.5) forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBOF(0xFFFFFF) forState:UIControlStateNormal];
//颜色绘制成图片
UIImage *dis_image = [UIImage qmui_imageWithColor:RGBAOF(0x0BBE06, 0.5)];
[doneButton setBackgroundImage:dis_image forState:UIControlStateDisabled];
UIImage *nor_image = [UIImage qmui_imageWithColor:RGBOF(0x0BBE06)];
[doneButton setBackgroundImage:nor_image forState:UIControlStateNormal];
doneButton.layer.masksToBounds = YES;
doneButton.layer.cornerRadius = 5;
//分割线
[divideLine setBackgroundColor:RGBOF(0xDEDEDE)];
}];
//图片预览
[self setPhotoPreviewPageUIConfigBlock:^(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel) {
//返回按钮
[backButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_back"] forState:UIControlStateNormal];
//选择按钮
[selectButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_nor"] forState:UIControlStateNormal];
[selectButton setImage:[UIImage qmui_imageWithColor:RGBOF(0x0BBE06) size:CGSizeMake(28, 28) cornerRadius:14] forState:UIControlStateSelected];
[selectButton setTitle:@"" forState:UIControlStateDisabled];
//原图按钮
[originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_normal"] forState:UIControlStateDisabled];//禁用
[originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_normal"] forState:UIControlStateNormal];//默认
[originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:@"photo_original_select"] forState:UIControlStateSelected];//选中
originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16];
[originalPhotoButton setTitleColor:RGBOF(0xB3B3B3) forState:UIControlStateDisabled];
[originalPhotoButton setTitleColor:RGBAOF(0xFFFFFF, 0.7) forState:UIControlStateNormal];
//原图内容隐藏
originalPhotoLabel.hidden = YES;
//完成按钮
doneButton.titleLabel.font = [UIFont systemFontOfSize:13];
[doneButton setTitle:@"完成" forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBOF(0xFFFFFF) forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBOF(0xFFFFFF) forState:UIControlStateNormal];
//颜色绘制成图片
UIImage *dis_image = [UIImage qmui_imageWithColor:RGBAOF(0x0BBE06, 0.5)];
[doneButton setBackgroundImage:dis_image forState:UIControlStateSelected];
UIImage *nor_image = [UIImage qmui_imageWithColor:RGBOF(0x0BBE06)];
[doneButton setBackgroundImage:nor_image forState:UIControlStateNormal];
doneButton.layer.masksToBounds = YES;
doneButton.layer.cornerRadius = 5;
}];
//视频预览
[self setVideoPreviewPageUIConfigBlock:^(UIButton *playButton, UIView *toolBar, UIButton *doneButton) {
//完成按钮
doneButton.titleLabel.font = [UIFont systemFontOfSize:13];
[doneButton setTitle:@"完成" forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBOF(0xFFFFFF) forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBOF(0xFFFFFF) forState:UIControlStateNormal];
//颜色绘制成图片
UIImage *dis_image = [UIImage qmui_imageWithColor:RGBAOF(0x0BBE06, 0.5)];
[doneButton setBackgroundImage:dis_image forState:UIControlStateSelected];
UIImage *nor_image = [UIImage qmui_imageWithColor:RGBOF(0x0BBE06)];
[doneButton setBackgroundImage:nor_image forState:UIControlStateNormal];
doneButton.layer.masksToBounds = YES;
doneButton.layer.cornerRadius = 5;
}];
//gif预览
[self setGifPreviewPageUIConfigBlock:^(UIView *toolBar, UIButton *doneButton) {
//完成按钮
doneButton.titleLabel.font = [UIFont systemFontOfSize:13];
[doneButton setTitle:@"完成" forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBOF(0xFFFFFF) forState:UIControlStateDisabled];
[doneButton setTitleColor:RGBOF(0xFFFFFF) forState:UIControlStateNormal];
//颜色绘制成图片
UIImage *dis_image = [UIImage qmui_imageWithColor:RGBAOF(0x0BBE06, 0.5)];
[doneButton setBackgroundImage:dis_image forState:UIControlStateSelected];
UIImage *nor_image = [UIImage qmui_imageWithColor:RGBOF(0x0BBE06)];
[doneButton setBackgroundImage:nor_image forState:UIControlStateNormal];
doneButton.layer.masksToBounds = YES;
doneButton.layer.cornerRadius = 5;
}];
//相册cell
[self setAssetCellDidSetModelBlock:^(CNTZAssetCell *cell, UIImageView *imageView, UIImageView *selectImageView, UILabel *indexLabel, UIView *bottomView, UILabel *timeLength, UIImageView *videoImgView) {
}];
//相簿
[self setAlbumCellDidSetModelBlock:^(CNTZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel) {
[posterImageView setBackgroundColor:[UIColor whiteColor]];
}];
/// 【自定义各页面/组件的frame】在界面viewDidLayoutSubviews/组件layoutSubviews后调用,允许外界修改frame等
//相册
[self setPhotoPickerPageDidLayoutSubviewsBlock:^(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine) {
CGRect frame = bottomToolBar.frame;
doneButton.frame = CGRectMake(frame.size.width - 60 - 13, frame.size.height /2 - 15 - (kVerticalBottomSafeHeight /2), 60, 30);
CGRect originalPhotoLabelFrame = originalPhotoLabel.frame;
CGFloat originalX = (bottomToolBar.frame.size.width - originalPhotoLabelFrame.size.width) /2;
CGFloat originalY = originalPhotoLabelFrame.origin.y;
originalPhotoButton.frame = CGRectMake(originalX, originalY, originalPhotoLabelFrame.size.width, originalPhotoLabelFrame.size.height);
}];
//图片预览
[self setPhotoPreviewPageDidLayoutSubviewsBlock:^(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel) {
[backButton setImage:[UIImage imageNamedFromMyBundle:@"navi_back"] forState:UIControlStateNormal];
CGRect frame = toolBar.frame;
doneButton.frame = CGRectMake(frame.size.width - 60 - 13, frame.size.height /2 - 15 - (kVerticalBottomSafeHeight /2), 60, 30);
}];
//视频预览
[self setVideoPreviewPageDidLayoutSubviewsBlock:^(UIButton *playButton, UIView *toolBar, UIButton *doneButton) {
CGRect frame = toolBar.frame;
doneButton.frame = CGRectMake(frame.size.width - 60 - 13, frame.size.height /2 - 15 - (kVerticalBottomSafeHeight /2), 60, 30);
}];
//gif预览
[self setGifPreviewPageDidLayoutSubviewsBlock:^(UIView *toolBar, UIButton *doneButton) {
CGRect frame = toolBar.frame;
doneButton.frame = CGRectMake(frame.size.width - 60 - 13, frame.size.height /2 - 15 - (kVerticalBottomSafeHeight /2), 60, 30);
}];
//相册cell
[self setAssetCellDidLayoutSubviewsBlock:^(CNTZAssetCell *cell, UIImageView *imageView, UIImageView *selectImageView, UILabel *indexLabel, UIView *bottomView, UILabel *timeLength, UIImageView *videoImgView) {
}];
//相簿
[self setAlbumCellDidLayoutSubviewsBlock:^(CNTZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel) {
}];
//设置图片个数
self.photoNumberIconImage = [UIImage new];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end