[objective-c]ELCImagePickerControllerを使ってカメラロールの写真を複数選択
ELCImagePickerControllerを使ってカメラロールの写真を複数選択
1) LibraryをLinkさせる
・プロジェクトを選択
・TARGETSを選択
・Build Phasesをクリック
・Link Binary With Librariesをクリック
・「+」をクリック
・AssetsLibrary.frameworkを選択して「add」
2)ヘッダファイルでimport
#import "ELCImagePickerController.h" #import "ELCAlbumPickerController.h"
3)実装
-(float)getFillRatio:(CGSize)sourceSize targetSize:(CGSize)targetSize{ CGFloat widthRatio = targetSize.width / sourceSize.width; CGFloat heightRatio = targetSize.height / sourceSize.height; return (widthRatio > heightRatio) ? widthRatio : heightRatio; } -(UIImage*)getResizeImageFill:(UIImage*)img size:(CGSize)_size{ CGFloat ratio=[self getFillRatio:img.size targetSize:_size]; CGSize resizedSize = CGSizeMake(roundf(img.size.width*ratio), roundf(img.size.height*ratio)); UIGraphicsBeginImageContext(resizedSize); [img drawInRect:CGRectMake(0, 0, resizedSize.width, resizedSize.height)]; UIImage* resizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resizedImage; } -(void)startPhotoSelect{ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { ELCAlbumPickerController *albumController = [[[ELCAlbumPickerController alloc] initWithNibName:@"ELCAlbumPickerController" bundle:[NSBundle mainBundle]]autorelease]; ELCImagePickerController *elcPicker = [[[ELCImagePickerController alloc] initWithRootViewController:albumController]autorelease]; [albumController setParent:elcPicker]; [elcPicker setDelegate:self]; [self presentModalViewController:elcPicker animated:YES]; } else { } } - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info { [self dismissModalViewControllerAnimated:YES]; if ([info count]<1) { return; } int i; NSMutableDictionary*d; CGSize imageSize=CGSizeMake(100, 100); for (i=0; i<[info count]; i++) { d=[info objectAtIndex:i]; UIImageView *imageview; imageview=[[UIImageView alloc] initWithImage:[self getResizeImageFill:[d objectForKey:UIImagePickerControllerOriginalImage] size:imageSize]]; [self.view addSubview:imageview]; imageview.frame=CGRectMake(20.0*i, 20.0*i, imageSize.width, imageSize.height); } } - (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker { [self dismissModalViewControllerAnimated:YES]; } //ここから実行 -(IBAction)whenTapBtn:(id)sender{ [self startPhotoSelect]; }
github:ELCImagePickerController
https://github.com/elc/ELCImagePickerController