I have 3 image views on my view controller. I have an option like choose from gallery or take a picture. Now, what I want is from the camera. I want to pick images by default, we can pick one, but I want three how can we achieve it.
Asked
Active
Viewed 599 times
2
-
1Did you check for existing answers in the community ? http://stackoverflow.com/questions/20756899/how-to-select-multiple-images-from-uiimagepickercontroller – Bharath Jul 27 '16 at 07:25
-
UIImagePickerController doesn't allow you to select multiple images. You could try a custom ImagePickerController such as this one: https://github.com/B-Sides/ELCImagePickerController but it might not work as expected as the class this library is built on (ALAssetsLibrary) has been deprecated as of iOS 9. – MShahmeer Jul 27 '16 at 07:26
-
`we can pick one, but I want three how can we achieve it` can you explain these line in brief – Anbu.Karthik Jul 27 '16 at 07:44
3 Answers
3
use Tag
Concept`
Step-1
Initially assign the tag for your each imageView as 1,2,3
and crete the one common method for open the UIImagePickerController
Step-2
create the gesture for each image
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tap];
call method like
- (IBAction)handleImageTap:(UIGestureRecognizer*)sender
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Attach image" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* pickFromGallery = [UIAlertAction actionWithTitle:@"Take a photo"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.view.tag = sender.view.tag;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:NULL];
}
}];
UIAlertAction* takeAPicture = [UIAlertAction actionWithTitle:@"Choose from gallery"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.view.tag = sender.view.tag;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:NULL];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
}];
[alertController addAction:pickFromGallery];
[alertController addAction:takeAPicture];
[alertController addAction:cancel];
[self presentViewController:alertController animated:YES completion:NULL];
}
Step-3
on that delegate method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
if(picker.view.tag == 1)
{
// assign the image to first
}
else if(picker.view.tag == 2)
{
// assign the image to second
}
else
{
// assign the image to third
}
}

Anbu.Karthik
- 82,064
- 23
- 174
- 143
-
@user3182143 - why we prepare third party , we can customize everything in our own code, and thanx a lot – Anbu.Karthik Jul 27 '16 at 07:36
-
-
1@Anbu.Karthik : I think original post is asking for picking three image with one attemp!! – Ketan Parmar Jul 27 '16 at 07:37
-
@Lion - no bro is not possible , but we can apply the three images in single clik – Anbu.Karthik Jul 27 '16 at 07:38
-
yeah but op is asking for that!!!! And it is possible by customization!! – Ketan Parmar Jul 27 '16 at 07:39
-
1Yes OP is asking for 3 images to be selected at a go and they be applied to 3 imageviews respectively. – Bhumit Mehta Jul 27 '16 at 07:40
-
If there is need like tap and pick image one by one then this answer is perfact with nice explanation!! – Ketan Parmar Jul 27 '16 at 07:42
-
-
1Btw questioner should use this approach because this is simpler. If there is three image view then he can pick three image one by one. There is no need to pick three image at once!!! – Ketan Parmar Jul 27 '16 at 07:45
0
You can write your own logic something like,
In didFinishPickingImage
increment one counter and don't dismiss image picker
control until counter reaches at 3 and store image every time n local storage like in document directory or temp directory.
Refer accepted answer of this so post for demonstration of what i have explained.
If you want to use third party library then ELCImagePickerController is better solution.

Community
- 1
- 1

Ketan Parmar
- 27,092
- 9
- 50
- 75
0
I recommended two Third-party to you to pick multiple images and deal with to as you can :-

Ahmed Abdallah
- 2,338
- 1
- 19
- 30