Latest 1.0.4
Homepage https://github.com/itheima-developer/HMImagePicker
License MIT
Platforms ios 8.0, requires ARC
Authors

HMImagePicker

Build Status
CocoaPods Compatible
Platform

轻量级图像选择框架

功能

  • 仿微信照片选择功能,支持横竖屏
  • UIImagePickerController 几乎完全一致的接口调用方式,上手容易
  • 使用 Photos 框架异步加载图片,内存消耗低

屏幕截图

HMImagePicker” alt=”” />
HMImagePicker” alt=”” />

系统支持

  • iOS 8.0+
  • Xcode 7.0

安装

CocoaPods

  • 进入终端,cd 到项目目录,输入以下命令,建立 Podfile
$ pod init
  • 在 Podfile 中输入以下内容:
platform :ios, '8.0'
use_frameworks!

target 'ProjectName' do
pod 'HMImagePicker'
end
  • 在终端中输入以下命令,安装或升级 Pod
# 安装 Pod,第一次使用
$ pod install

# 升级 Pod,后续使用
$ pod update

使用

Objective-C

  • 导入框架
@import HMImagePicker;
  • 在私有扩展中定义属性
@interface MainViewController () <HMImagePickerControllerDelegate>
/// 选中照片数组
@property (nonatomic) NSArray *images;
/// 选中资源素材数组,用于定位已经选择的照片
@property (nonatomic) NSArray *selectedAssets;
@end
  • 在选择按钮的方法中,实现以下代码
- (IBAction)clickSelectPhotoButton {
    HMImagePickerController *picker = [[HMImagePickerController alloc] initWithSelectedAssets:self.selectedAssets];

    // 设置图像选择代理
    picker.pickerDelegate = self;
    // 设置目标图片尺寸
    picker.targetSize = CGSizeMake(600, 600);
    // 设置最大选择照片数量
    picker.maxPickerCount = 9;

    [self presentViewController:picker animated:YES completion:nil];
}
  • 遵守协议
@interface MainViewController () <HMImagePickerControllerDelegate>
  • 实现协议方法
#pragma mark - HMImagePickerControllerDelegate
- (void)imagePickerController:(HMImagePickerController *)picker
      didFinishSelectedImages:(NSArray<UIImage *> *)images
               selectedAssets:(NSArray<PHAsset *> *)selectedAssets {

    // 记录图像,方便在 CollectionView 显示
    self.images = images;
    // 记录选中资源集合,方便再次选择照片定位
    self.selectedAssets = selectedAssets;

    [self.collectionView reloadData];

    [self dismissViewControllerAnimated:YES completion:nil];
}

Latest podspec

{
    "name": "HMImagePicker",
    "version": "1.0.4",
    "summary": "u8f7bu91cfu7ea7u56feu50cfu9009u62e9u6846u67b6",
    "homepage": "https://github.com/itheima-developer/HMImagePicker",
    "license": "MIT",
    "authors": {
        "u9ed1u9a6cu7a0bu5e8fu5458": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/itheima-developer/HMImagePicker.git",
        "tag": "1.0.4"
    },
    "source_files": "HMImagePicker/HMImagePicker/*.{h,m}",
    "resources": "HMImagePicker/HMImagePicker/HMImagePicker.bundle",
    "requires_arc": true
}

Pin It on Pinterest

Share This