# Customizing the toolbar in our iOS PDF viewer

### iOS

[iOS](https://www.nutrient.io/guides/ios/user-interface/main-toolbar.md)

### visionOS

[visionOS](https://www.nutrient.io/guides/ios/user-interface/main-toolbar-visionos.md)

By default, Nutrient works with `UINavigationController` to show the `UINavigationBar` as the toolbar. You can use regular `UIBarButtonItem` objects to populate the navigation bar or the (bottom) view controller toolbar.

Since Nutrient uses custom toolbar logic (for example, when the thumbnails are displayed, we hide the annotation bar button item), [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) has a custom [`navigationItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/navigationitem) that you can use to configure the bar button items for different view modes. If you use the `leftBarButtonItems` and `rightBarButtonItems` API from `UINavigationItem`, you will set the items for all view modes. Most likely, this is not what you want. Instead, use [`setLeftBarButtonItems(_:for:animated:)`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/navigationitem/setleftbarbuttonitems(_:for:animated:)) or the [equivalent for the right side](https://www.nutrient.io/api/ios/documentation/pspdfkitui/navigationitem/setrightbarbuttonitems(_:for:animated:)) and specify the view mode you want to alter with that call.

If the view mode you change is the one that is currently visible, the navigation bar will update to represent these changes.

Nutrient provides [several custom bar button items](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) for the most common features:

| Property                       | Description                                                                                                                                                                                                                                                                          |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`closeButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/closebuttonitem)          | Closes the [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) if pushed modally. Default entry in `leftBarButtonItems`.                                                                                                                                                                                         |
| [`outlineButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/outlinebuttonitem)        | Presents the [`OutlineViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/outlineviewcontroller) if there is an outline defined in the PDF. Default entry in `rightBarButtonItems`.                                                                                                                                                          |
| [`searchButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/outlinebuttonitem)         | Shows the [`SearchViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/searchviewcontroller) or the [`InlineSearchManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/inlinesearchmanager) for searching text in the current `document`. See [`SearchMode`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/searchmode) in [`PDFConfiguration`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfconfiguration) to configure this. Default entry in `rightBarButtonItems`.                                                        |
| [`thumbnailsButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/thumbnailsbuttonitem)     | Toggles between the document and the thumbnail view state. See [`ViewMode`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/viewmode) and [`setViewMode(_:animated:)`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/setviewmode(_:animated:)). Default entry in `rightBarButtonItems`.                                                                                                                            |
| [`documentEditorButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/documenteditorbuttonitem) | Toggles between the document and the Document Editor view state.                                                                                                                                                                                                                     |
| [`printButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/printbuttonitem)          | Presents the `UIPrintInteractionController` for document printing. Only displayed if the document is allowed to be printed. See `allowsPrinting` in [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document). You should use the [`activityButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/activitybuttonitem) instead. Share to `UIActivity.ActivityType.PSPDFActivityTypeOpenIn`. |
| [`openInButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/openinbuttonitem)         | Presents the `UIDocumentInteractionController` controller to open documents in other apps. You should use the [`activityButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/activitybuttonitem) instead.                                                                                                                                      |
| [`emailButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/emailbuttonitem)          | Presents the `MFMailComposeViewController` to send the document via email. Will only work when sending emails is configured on the device. You should use the [`activityButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/activitybuttonitem) instead. Share to `UIActivity.ActivityType.mail`.                                             |
| [`messageButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/messagebuttonitem)        | Presents the `MFMessageComposeViewController` to send the document via SMS/iMessage. Will only work if iMessage or SMS is configured on the device. You should use the [`activityButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/activitybuttonitem) instead. Share to `UIActivity.ActivityType.message`.                                 |
| [`annotationButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/annotationbuttonitem)     | Shows and hides the [`AnnotationToolbar`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationtoolbar) toolbar for creating annotations. Requires the `Features.annotationEditing` feature flag.                                                                                                                                                |
| [`bookmarkButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/bookmarkbuttonitem)       | Presents the [`BookmarkViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/bookmarkviewcontroller) for creating/editing/viewing bookmarks.                                                                                                                                                                                                    |
| [`brightnessButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/brightnessbuttonitem)     | Presents the [`BrightnessViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/brightnessviewcontroller) to control screen brightness. iOS has a similar feature in the Control Center, but Nutrient includes an additional software brightener.                                                                                                  |
| [`activityButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/activitybuttonitem)       | Presents the `UIActivityViewController` for various actions, including many of the above button items. You can configure which activities are included and excluded by setting [`applicationActivities`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/documentsharingconfiguration/applicationactivities) and [`excludedActivityTypes`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/documentsharingconfiguration/excludedactivitytypes) in [`DocumentSharingConfiguration`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/documentsharingconfiguration).    |

## Positioning buttons

When setting navigation button items on either the left or the right side, Nutrient will check that no item on the left side is already set on the right side and vice versa, and it will throw an assertion if items on one side are also on the other side.

Nutrient iOS SDK distributes the default navigation button items into a corresponding [`ViewMode`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/viewmode) as follows:

| View mode         | Default right buttons                                                                                         |
| ----------------- | ------------------------------------------------------------------------------------------------------------- |
| `.document`       | `thumbnailsButtonItem`, `activityButtonItem`, `outlineButtonItem`, `searchButtonItem`, `annotationButtonItem` |
| `.documentEditor` | `thumbnailsButtonItem`, `documentEditorButtonItem`                                                            |
| `.thumbnails`     | `thumbnailsButtonItem`, `documentEditorButtonItem`                                                            |

This means that if you ever want to have, for instance, the `outlineButton` on the left rather than on the right, you first need to modify the buttons set on the right side to remove the `outlineButton` and then set the left items:

### SWIFT

```swift

// First clean up the buttons on the right.
controller.navigationItem.setRightBarButtonItems([], for:.document, animated: false)

// Then set the left buttons.
let leftButtons = [controller.settingsButtonItem, controller.outlineButtonItem]
controller.navigationItem.setLeftBarButtonItems(leftButtons, for:.document, animated: false)

```

### OBJECTIVE-C

```objc

// First clean up the buttons on the right.
[controller.navigationItem setRightBarButtonItems:@[] forViewMode:PSPDFViewModeDocument animated:NO];

// Then set the left buttons.
NSArray *leftButtons = @[controller.settingsButtonItem, controller.outlineButtonItem];
[controller.navigationItem setLeftBarButtonItems:leftButtons forViewMode:PSPDFViewModeDocument animated:NO];

```

## Customizing button appearance

Instead of trying to customize existing bar button items, it’s better to create your own bar button item and connect both `target` and `action` from the predefined buttons that we offer to get both the same tap behavior and complete customizability in terms of appearance.

If you want to call your own code before our stock code is invoked, you can set the target/action to your method and then call the stock method of the bar button item. Note that the spec allows for an optional sender parameter on target/action pairs, so to be absolutely correct, you should use a helper like the [`psc_targetActionBlock`](https://gist.github.com/steipete/faf0c5e4dc79dfb3fc173b4e91475409) that we ship in Nutrient Catalog. Our internal methods define a sender parameter, but this is a detail your code should not rely on.

## Button visibility

When `document` is `nil` or `document.isValid` returns `NO`, most buttons will be disabled and not displayed by default. If you need a button to always be visible, add your bar buttons to the [`barButtonItemsAlwaysEnabled`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/barbuttonitemsalwaysenabled) array. By default, this contains the `closeButtonItem`.

Changing any of these bar button-related properties will trigger a reload of the gallery.

## Hiding the close button

The close button, used to dismiss [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller) when pushed modally, is added automatically to `leftBarButtonItems`. If you choose to manage the close behavior yourself, or if you just want to hide the close button, you can set [`closeBarButtonItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/navigationitem/closebarbuttonitem) on the [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller)’s [`navigationItem`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/navigationitem) to `nil`.

## Hiding the toolbar completely

The navigation toolbar used in the standard configuration of Nutrient can be removed via the [`setNavigationBarHidden(_:animated:)`](https://developer.apple.com/documentation/uikit/uinavigationcontroller/1621885-setnavigationbarhidden) call from the standard `UINavigationController` that displays the `PDFViewController`. Since the `PDFViewController` also has logic to show/hide the HUD, you need to set `PDFConfiguration.userInterfaceViewMode` to `UserInterfaceViewMode.always`.

Alternatively, you can subclass the `PDFViewController` to make sure that the navigation bar is always hidden:

### SWIFT

```swift

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    self.navigationController?.setNavigationBarHidden(true, animated: false)
}

```

### OBJECTIVE-C

```objc

- (void)viewWillLayoutSubviews {
	[super viewWillLayoutSubviews];

	[self.navigationController setNavigationBarHidden:YES animated:NO];
}

```
---

## Related pages

- [Customizing PDF viewer styling on iOS](/guides/ios/customizing-the-interface/appearance-styling.md)
- [Editing PDFs in our iOS viewer](/guides/ios/features/document-editor-ui.md)
- [Localization: Change languages in our iOS PDF viewer](/guides/ios/features/localization.md)
- [Customizing our iOS PDF viewer](/guides/ios/user-interface.md)
- [Customizing the toolbar in our visionOS PDF viewer](/guides/ios/user-interface/main-toolbar-visionos.md)
- [Overriding classes in our iOS viewer](/guides/ios/getting-started/overriding-classes.md)
- [Customizing menus on iOS](/guides/ios/customizing-the-interface/customizing-menus.md)
- [Customize electronic signatures UI on iOS](/guides/ios/signatures/customizing-the-signature-user-interface.md)

