iOS-TZImagePickerController使用,调用相册,实现多选图片

时间:2024-03-13 09:36:19

安装pod 

在Podfile文件中新增

  pod 'TZImagePickerController'

添加好之后 pod install安装 

TZImagePickerController使用

引入头文件

#import <TZImagePickerController/TZImagePickerController.h>

@interface HandleMsgPictureView () <UINavigationControllerDelegate, UIImagePickerControllerDelegate, TZImagePickerControllerDelegate>


@end

唤起相册

- (void)pushTZImagePickerController {
    //能选择的最大图片数
    NSInteger maxCount = 4 - self.photos.count;
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:maxCount columnNumber:4 delegate:self pushPhotoPickerVc:YES];
    imagePickerVc.isSelectOriginalPhoto = NO;
    [imagePickerVc setUiImagePickerControllerSettingBlock:^(UIImagePickerController *imagePickerController) {
        imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
    }];
    // 修改 字体颜色为黑色
    [imagePickerVc.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
    imagePickerVc.navigationBar.barTintColor = kWhiteColor;
    imagePickerVc.barItemTextColor = kBlackColor;
    imagePickerVc.allowPickingVideo = NO;
    imagePickerVc.allowPickingImage = YES;
    imagePickerVc.allowPickingOriginalPhoto = NO;
    imagePickerVc.allowPickingGif = NO;
    imagePickerVc.allowPickingMultipleVideo = NO;// 是否可以多选视频
    // 设置是否显示图片序号
    imagePickerVc.showSelectedIndex = YES;
    //  照片排列按修改时间升序
    imagePickerVc.sortAscendingByModificationDate = YES;
    imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
    if (@available(iOS 13.0, *)) {
        imagePickerVc.statusBarStyle = UIStatusBarStyleDarkContent;
    } else {
        imagePickerVc.statusBarStyle = UIStatusBarStyleDefault;
    }
    WeakSelf
    // 你可以通过block或者代理,来得到用户选择的照片.
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        //自定义的数据处理
        [weakSelf.photos addObjectsFromArray:photos];
        [self loadData];
    }];
   
    [self.currentViewController presentViewController:imagePickerVc animated:YES completion:nil];
}

/// 用户点击了取消
- (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker {
     NSLog(@"cancel");
}