Latest 0.0.3
Homepage https://github.com/MeetDay/WCImagePicker
License MIT
Platforms ios 9.0, requires ARC
Frameworks Photos, PhotosUI
Authors

[WCImagePicker]() [WCImagePicker]() [WCImagePicker]() [WCImagePicker]() [WCImagePicker]() [WCImagePicker]()

简易好用的图片选择器

WCImagePickerWCImagePickerWCImagePicker

Installation

  • CocoaPods

  1. 在 Podfile 中添加pod 'WCImagePicker'
  2. 执行 pod installpod update
  3. 导入 #import <WCImagePicker/WCImagePicker.h>
  • 手动安装

  1. ​下载WCImagePickerDemo。
  2. 将WCImagePicker文件夹中的源代码添加(拖放)到你的工程。
  3. 导入#import "WCImagePicker.h"头文件即可。

Usage

WCImagePicker使用:

WCImagePickerController *imagePicker = [[WCImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaType = WCImagePickerImageTypeImage;
imagePicker.minimumNumberOfSelectionAsset = 1;
imagePicker.maximumNumberOfSelectionAsset = 9;

[self presentViewController:imagePicker animated:YES completion:nil];

自定义WCImagePickerController样式:

如果想自定义WCImagePickerController的样式,你可以创建WCImagePickerAppearance实例,给其属性赋值。在实例化WCImagePickerController之前调用setupImagePickerAppearance:

+ (void)setupImagePickerAppearance:(WCImagePickerAppearance *)imagePickerAppearance;

WCImagePickerAppearance简单使用:

WCImagePickerAppearance *imagePickerAppearance = [[WCImagePickerAppearance alloc] init];
imagePickerAppearance.cancelButtonText = @"退出";
imagePickerAppearance.finishedButtonDisableBackgroundColor = [UIColor grayColor];
[WCImagePickerController setupImagePickerAppearance:imagePickerAppearance];

设置更多可配置的属性,请查阅WCImagePickerAppearance

WCImagePickerController的代理方法 (WCImagePickerControllerDelegate)

实现了wc_imagePickerController:didFinishPickingAssets:代理方法。当用户点击 “完成” (即完成图片选择)时,此代理方法被调用。

/**
 选择完图片或视频后回调并回传选中的资源

 @param imagePicker 资源选择器
 @param assets 选中的资源
 */
- (void)wc_imagePickerController:(WCImagePickerController *)imagePicker didFinishPickingAssets:(NSArray<PHAsset *> *)assets {
  for (PHAsset *asset in assets) {
    // do something with the asset
  }
  [self dismissViewControllerAnimated:YES completion:nil];
}

实现了wc_imagePickerControllerDidCancel:代理方法。当用户点击 “取消” 时,此代理方法被调用。

/**
 点击取消后调用

 @param imagePicker 资源选择器
 */
- (void)wc_imagePickerControllerDidCancel:(WCImagePickerController *)imagePicker {
  // 
  [self dismissViewControllerAnimated:YES completion:nil];
}

实现以下代理方法,能处理用户选择Asset的选中状态。

/**
 判断是否应该选中该资源

 @param imagePicker 资源选择器
 @param asset 资源(图片或视频)
 @return 是否应该选中
 */
- (BOOL)wc_imagePickerController:(WCImagePickerController *)imagePicker shouldSelectAsset:(PHAsset *)asset;

/**
 asset选中时回调

 @param imagePicker 资源选择器
 @param asset 资源(图片或视频)
 */
- (void)wc_imagePickerController:(WCImagePickerController *)imagePicker didSelectAsset:(PHAsset *)asset;

/**
 asset取消选中时回调

 @param imagePicker 资源选择器
 @param asset 资源(图片或视频)
 */
- (void)wc_imagePickerController:(WCImagePickerController *)imagePicker didDeselectAsset:(PHAsset *)asset;

WCImagePickerController filter option

只选择图片

WCImagePickerController *imagePicker = [[WCImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaType = WCImagePickerImageTypeImage;
imagePicker.minimumNumberOfSelectionAsset = 1;
imagePicker.maximumNumberOfSelectionAsset = 9;

只选择视频

WCImagePickerController *imagePicker = [[WCImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaType = WCImagePickerImageTypeVideo;
imagePicker.minimumNumberOfSelectionAsset = 1;
imagePicker.maximumNumberOfSelectionAsset = 3;

选择图片和视频

WCImagePickerController *imagePicker = [[WCImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaType = WCImagePickerImageTypeAny;
imagePicker.minimumNumberOfSelectionAsset = 1;
imagePicker.maximumNumberOfSelectionAsset = 20;

Grid Size

可用numberOfColumnsInPortraitnumberOfColumnsInLandscape改变grid size。

// grid size 默认值
imagePicker.numberOfColumnsInPortrait = 4;
imagePicker.numberOfColumnsInLandscape = 7;

选中资源(图片或视频)达到最大数量时未选中资源是否显示遮罩

// 默认:YES
imagePicker.showAssetMaskWhenMaximumLimitReached = YES;

选中资源(图片或视频)达到最大数量时是否显示警示弹窗

// 默认:YES
imagePicker.showWarningAlertWhenMaximumLimitReached = YES;

是否显示没有资源(图片或视频)的相册

// 默认:NO
imagePicker.showPhotoAlbumWithoutAssetResources = NO;

更换相册时是否移除已选中的资源(图片或视频)

// 默认:YES
imagePicker.shouldRemoveAllSelectedAssetWhenAlbumChanged = YES;

是否允许手指在屏幕上滑动时选中资源(图片或视频)

// 默认:NO
imagePicker.fingerMovingToAssetForSelectionEnable = NO;

Change Log

  • V0.0.3 – 修复了发布至CocoaPods后没有xib的问题。

Contact

LICENSE

Latest podspec

{
    "name": "WCImagePicker",
    "version": "0.0.3",
    "summary": "u7b80u6613u597du7528u7684u56feu7247u9009u62e9u5668(Simple and easy for image picker)",
    "homepage": "https://github.com/MeetDay/WCImagePicker",
    "license": "MIT",
    "authors": {
        "wangchao": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/MeetDay/WCImagePicker.git",
        "tag": "0.0.3"
    },
    "source_files": "WCImagePicker/*.{h,m}",
    "resource_bundles": {
        "WCImagePicker": "WCImagePicker/*.{xib,xcassets}"
    },
    "frameworks": [
        "Photos",
        "PhotosUI"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This