CNImagePickerController.m 14.8 KB
//
//  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