Customize View Control Modals on iOS

There are a lot of view controllers presented modally in PSPDFKit, and you have the ability to customize the behavior and look of all of them. So in this article, you will learn how to achieve the exact behavior and look you desire.

Hide the Close Button

We automatically add a close button to all modally presented view controllers. If you don’t want that button or if you want to customize this behavior, you hide the close button in two different ways (detailed below).

Hide the Close Button for PSPDFViewController

To hide the close button on a modally presented PSPDFViewController, set the closeBarButtonItem of the navigationItem to nil.

Hide the Close Button on a View Controller Presented from PSPDFViewController

To hide the close button on a view controller presented from PSPDFViewController, override presentViewController:options:animated:sender:completion: in your PSPDFViewController subclass and edit the options dictionary to set PSPDFPresentationCloseButtonKey to false.

In the following code snippet, we hide the close button only for presented instances of PSPDFNoteAnnotationViewController. Be aware that if you hide the close button without adding a custom close button, there is no other way to dismiss the view controller:

override func present(_ controller: UIViewController, options: [String: Any]? = nil, animated: Bool, sender: Any?, completion: (() -> Void)? = nil) -> Bool {
    var customOptions = options
    if controller is PSPDFNoteAnnotationViewController {
        customOptions?[PSPDFPresentationCloseButtonKey] = false
    }
    return super.present(controller, options: customOptions, animated: animated, sender: sender, completion: completion)
}
- (BOOL)presentViewController:(UIViewController *)controller options:(nullable NSDictionary<NSString *, id> *)options animated:(BOOL)animated sender:(nullable id)sender completion:(void (^)(void))completion {
    NSMutableDictionary<NSString *, id> *customOptions = options.mutableCopy;
    if ([controller isKindOfClass:PSPDFNoteAnnotationViewController.class]) {
        customOptions[PSPDFPresentationCloseButtonKey] = @NO;
    }
    return [super presentViewController:controller options:customOptions animated:animated sender:sender completion:completion];
}