Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling the photo library button on the UIImagePickerController

Does anyone know how to enable the photo album button on the UIImagePickerController when its in the camera mode? Like how the camera app on on the iphone can toggle between image and video taking and also has the button to view the photo library?

like image 841
MBU Avatar asked Dec 16 '11 01:12

MBU


People also ask

What is an image picker?

expo-image-picker provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the camera.

What is UIImagePickerController?

A view controller that manages the system interfaces for taking pictures, recording movies, and choosing items from the user's media library.


1 Answers

This can be done via the following lines:

- (void) navigationController: (UINavigationController *) navigationController  willShowViewController: (UIViewController *) viewController animated: (BOOL) animated {
    if (imagePickerController.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
        UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(showCamera:)];
        viewController.navigationItem.rightBarButtonItems = [NSArray arrayWithObject:button];
    } else {
        UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle:@"Library" style:UIBarButtonItemStylePlain target:self action:@selector(showLibrary:)];
        viewController.navigationItem.leftBarButtonItems = [NSArray arrayWithObject:button];
        viewController.navigationItem.title = @"Take Photo";
        viewController.navigationController.navigationBarHidden = NO; // important
    }
}

- (void) showCamera: (id) sender {
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}

- (void) showLibrary: (id) sender {
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
like image 134
epsilontik Avatar answered Sep 21 '22 11:09

epsilontik