---
title: "Separate Photo Library and Camera actions"
canonical_url: "https://www.nutrient.io/guides/ios/knowledge-base/separate-photo-library-and-camera-actions/"
md_url: "https://www.nutrient.io/guides/ios/knowledge-base/separate-photo-library-and-camera-actions.md"
last_updated: "2026-05-14T16:53:43.872Z"
description: "Learn to implement separate buttons for adding image annotations from the Photo Library and Camera using UIImagePickerController and custom subclasses in Swift."
---

It’s possible to add two separate buttons for adding image annotations from the Photo Library and Camera. The most flexible way to achieve this is to present `UIImagePickerController` or `PHPickerViewController` from your own code and then add a [`StampAnnotation`](https://www.nutrient.io/api/ios/documentation/pspdfkit/stampannotation) with the image you get from the picker.

Alternatively, you can achieve this with Nutrient with subclasses of Nutrient’s [`ImagePickerController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/imagepickercontroller) that [only allow one source type](https://www.nutrient.io/guides/ios/miscellaneous/image-picker.md#source-type). For example:

```swift

class OnlyPhotoLibraryPickerController: ImagePickerController {
    override class func availableImagePickerSourceTypes() -> [NSNumber] {
        return [NSNumber(value: UIImagePickerController.SourceType.photoLibrary.rawValue)]
    }
}

```

In a button action method in a subclass of [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller), register the subclass just before showing the image picker:

```swift

@objc func togglePhotoLibrary(_ sender: UIBarButtonItem) {
    self.updateConfiguration {
        $0.overrideClass(ImagePickerController.self, with: OnlyPhotoLibraryPickerController.self)
    }
    self.annotationStateManager.toggleImagePickerController(sender, presentationOptions: nil)
}

```

Here’s a complete subclass of `PDFViewController` that adds two separate buttons — one to import images from the Photo Library, and one to import from the Camera:

### SWIFT

```swift

class SeparateImagePickersPDFViewController: PDFViewController {
    override func commonInit(with document: Document?, configuration: PDFConfiguration) {
        super.commonInit(with: document, configuration: configuration)

        var leftBarButtonItems = navigationItem.leftBarButtonItems(for:.document)?? []
        leftBarButtonItems += [
            UIBarButtonItem(title: "Library", style:.plain, target: self, action: #selector(togglePhotoLibrary)),

            UIBarButtonItem(title: "Camera", style:.plain, target: self, action: #selector(toggleCamera)),

        ]
        navigationItem.setLeftBarButtonItems(leftBarButtonItems, for:.document, animated: false)
        navigationItem.leftItemsSupplementBackButton = true
    }

    @objc private func togglePhotoLibrary(_ sender: UIBarButtonItem) {
        updateConfiguration {
            $0.overrideClass(ImagePickerController.self, with: OnlyPhotoLibraryPickerController.self)
        }
        annotationStateManager.toggleImagePickerController(sender, presentationOptions: nil)
    }

    @objc private func toggleCamera(_ sender: UIBarButtonItem) {
        updateConfiguration {
            $0.overrideClass(ImagePickerController.self, with: OnlyCameraPickerController.self)
        }
        annotationStateManager.toggleImagePickerController(sender, presentationOptions: nil)
    }
}

private class OnlyPhotoLibraryPickerController: ImagePickerController {
    override class func availableImagePickerSourceTypes() -> [NSNumber] {
        return [NSNumber(value: UIImagePickerController.SourceType.photoLibrary.rawValue)]
    }
}

private class OnlyCameraPickerController: ImagePickerController {
    override class func availableImagePickerSourceTypes() -> [NSNumber] {
        return [NSNumber(value: UIImagePickerController.SourceType.camera.rawValue)]
    }
}

```

### OBJECTIVE-C

```objc

@interface SeparateImagePickersPDFViewController : PSPDFViewController
@end
@interface OnlyPhotoLibraryPickerController : PSPDFImagePickerController
@end
@interface OnlyCameraPickerController : PSPDFImagePickerController
@end

@implementation SeparateImagePickersPDFViewController

- (void)commonInitWithDocument:(PSPDFDocument *)document configuration:(PSPDFConfiguration *)configuration {
    [super commonInitWithDocument:document configuration:configuration];

    NSMutableArray<UIBarButtonItem *> *leftBarButtonItems = [NSMutableArray arrayWithArray:[self.navigationItem leftBarButtonItemsForViewMode:PSPDFViewModeDocument]];
    [leftBarButtonItems addObjectsFromArray:@[
        [[UIBarButtonItem alloc] initWithTitle:@"Library" style:UIBarButtonItemStylePlain target:self action:@selector(togglePhotoLibrary:)],
        [[UIBarButtonItem alloc] initWithTitle:@"Camera" style:UIBarButtonItemStylePlain target:self action:@selector(toggleCamera:)],
    ]];
    [self.navigationItem setLeftBarButtonItems:leftBarButtonItems forViewMode:PSPDFViewModeDocument animated:NO];
    self.navigationItem.leftItemsSupplementBackButton = YES;
}

- (void)togglePhotoLibrary:(UIBarButtonItem *)sender {
    [self updateConfigurationWithBuilder:^(PSPDFConfigurationBuilder *builder) {
        [builder overrideClass:PSPDFImagePickerController.class withClass:OnlyPhotoLibraryPickerController.class];
    }];
    [self.annotationStateManager toggleImagePickerController:sender presentationOptions:nil];
}

- (void)toggleCamera:(UIBarButtonItem *)sender {
    [self updateConfigurationWithBuilder:^(PSPDFConfigurationBuilder *builder) {
        [builder overrideClass:PSPDFImagePickerController.class withClass:OnlyCameraPickerController.class];
    }];
    [self.annotationStateManager toggleImagePickerController:sender presentationOptions:nil];
}

@end

@implementation OnlyPhotoLibraryPickerController

+ (NSArray<NSNumber *> *)availableImagePickerSourceTypes {
    return @[@(UIImagePickerControllerSourceTypePhotoLibrary)];
}

@end

@implementation OnlyCameraPickerController

+ (NSArray<NSNumber *> *)availableImagePickerSourceTypes {
    return @[@(UIImagePickerControllerSourceTypeCamera)];
}

@end

```
---

## Related pages

- [Adjusting Size Of Popovers](/guides/ios/knowledge-base/adjusting-size-of-popovers.md)
- [Fix app store connect operation errors in Xcode](/guides/ios/knowledge-base/app-store-connect-operation-errors.md)
- [Archive Errors Cocoapods](/guides/ios/knowledge-base/archive-errors-cocoapods.md)
- [Customize your iOS navigation bar above crop UI](/guides/ios/knowledge-base/customize-the-navigation-bar-in-crop.md)
- [Adding Swipe Gesture Recognizer](/guides/ios/knowledge-base/adding-swipe-gesture-recognizer.md)
- [Configuring Scroll Views](/guides/ios/knowledge-base/configuring-scroll-views.md)
- [Debugging Issues](/guides/ios/knowledge-base/debugging-issues.md)
- [Adding Vector Image Annotation From Instant Json](/guides/ios/knowledge-base/adding-vector-image-annotation-from-instant-json.md)
- [Disabling Auto Opening Comments](/guides/ios/knowledge-base/disabling-auto-opening-comments.md)
- [Customizing Annotation Toolbar Frame](/guides/ios/knowledge-base/customizing-annotation-toolbar-frame.md)
- [Customize Share Sheet Apps](/guides/ios/knowledge-base/customize-share-sheet-apps.md)
- [Customize PDF rendering on iOS](/guides/ios/knowledge-base/customize-document-rendering.md)
- [Disabling Directional Lock](/guides/ios/knowledge-base/disabling-directional-lock.md)
- [Disabling Text Selection](/guides/ios/knowledge-base/disabling-text-selection.md)
- [Disabling Adding Pages With Images](/guides/ios/knowledge-base/disabling-adding-pages-with-images.md)
- [Gatekeeper Alerts Mac Catalyst](/guides/ios/knowledge-base/gatekeeper-alerts-mac-catalyst.md)
- [Customize action sheet appearance on iOS links](/guides/ios/knowledge-base/hide-or-customize-the-action-sheet-link-long-press.md)
- [Drawing An Upright Stamp Annotation On A Rotated Page](/guides/ios/knowledge-base/drawing-an-upright-stamp-annotation-on-a-rotated-page.md)
- [How Do I Change How To Open Links](/guides/ios/knowledge-base/how-do-i-change-how-to-open-links.md)
- [Generate PDFs from complex HTML](/guides/ios/knowledge-base/generating-pdf-from-complex-html.md)
- [How Do I Customize Search Results](/guides/ios/knowledge-base/how-do-i-customize-search-results.md)
- [Adding a custom view controller in iOS](/guides/ios/knowledge-base/how-do-i-add-custom-controller-to-containerviewcontroller.md)
- [How Do I Migrate From Cocoapods To Spm](/guides/ios/knowledge-base/how-do-i-migrate-from-cocoapods-to-spm.md)
- [How Do I Customize The Annotation Inspector](/guides/ios/knowledge-base/how-do-i-customize-the-annotation-inspector.md)
- [How Do I Download Pspdfkit As Fat Frameworks](/guides/ios/knowledge-base/how-do-i-download-pspdfkit-as-fat-frameworks.md)
- [Get notifications for unlocked password-protected PDFs](/guides/ios/knowledge-base/how-do-i-get-notified-when-a-password-protected-document-is-unlocked.md)
- [How Do I Present A Pspdftabbedviewcontroller In Cordova](/guides/ios/knowledge-base/how-do-i-present-a-pspdftabbedviewcontroller-in-cordova.md)
- [Other dependencies.](/guides/ios/knowledge-base/how-do-i-migrate-from-carthage-to-spm.md)
- [Capture ink signatures using SignatureViewController](/guides/ios/knowledge-base/how-do-i-get-an-image-from-signatureviewcontroller.md)
- [How Do I Remove The Sign Arrow From The Signature Form Field](/guides/ios/knowledge-base/how-do-i-remove-the-sign-arrow-from-the-signature-form-field.md)
- [How Do I Select Or Deselect An Annotation Programmatically](/guides/ios/knowledge-base/how-do-i-select-or-deselect-an-annotation-programmatically.md)
- [How to add annotations programmatically in iOS](/guides/ios/knowledge-base/how-do-i-programmatically-add-annotation-to-the-saved-annotations-list.md)
- [Fixing library not found issues in iOS apps](/guides/ios/knowledge-base/library-not-found-swiftpm.md)
- [Fix incorrect page color in night appearance mode](/guides/ios/knowledge-base/how-do-i-reset-custom-document-render-options-before-change-the-appearance-mode.md)
- [Block annotation editing and deletion in iOS](/guides/ios/knowledge-base/prevent-annotation-editing-allow-manipulation.md)
- [Creating invisible digital signatures on iOS](/guides/ios/knowledge-base/invisible-signature.md)
- [Search Special Characters](/guides/ios/knowledge-base/search-special-characters.md)
- [Processor Write To File Url](/guides/ios/knowledge-base/processor-write-to-file-url.md)
- [Setting The Initial Page Selection When Sharing](/guides/ios/knowledge-base/setting-the-initial-page-selection-when-sharing.md)
- [Zoom to specific PDF annotations easily](/guides/ios/knowledge-base/zoom-to-specific-annotation.md)
- [Showing Annotation Tools In The Main Toolbar](/guides/ios/knowledge-base/showing-annotation-tools-in-the-main-toolbar.md)
- [How to store electronic signatures using Instant JSON](/guides/ios/knowledge-base/store-electronic-signatures-from-instant-json-annotations.md)
- [Suppressing File Coordination Alerts](/guides/ios/knowledge-base/suppressing-file-coordination-alerts.md)

