> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/ios/annotation/annotation-toolbar-i.md).

# Customize annotation toolbar in iOS viewer

Learn how to use the PTAnnotationToolbar class to create and switch between annotation tools conveniently. Customize the toolbar and control its behavior with the PTAnnotationToolbarDelegate protocol.

The [`PTAnnotationToolbar`](https://sdk.apryse.com/api/ios/Classes/PTAnnotationToolbar.html) class is a [`UIToolbar`](https://developer.apple.com/uikit/uitoolbar/) consisting of various annotation creation tools. With the annotation toolbar, users are able to conveniently create and switch between different tools.

![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-ca07ba2bc5f78ee3b353db645048f76fef09138c%2F9c15e4367b2e3531129ca48c5ab0492fccde09a2-2556x1179.png?alt=media)

The annotation toolbar control is part of the Tools library, so make sure you have [added it to your project](/ios/ui-customization/setup.md).

{% hint style="info" %}
**Due to space limitations, only a limited number of tools will show up in portrait mode on smaller devices. See the customization section of this guide for more details on how to customize this.**
{% endhint %}

| Scenario                                         | Annotation Toolbar                                                                                                                                                                                                                               |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Small devices in landscape mode + Tablet devices | ![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-2d0f33e6431a2528823efc9022b984e0820b010d%2Fdecc5c514a4f4705a4d845543872a2965f9f5e3c-1466x184.png?alt=media) |
| Small devices in portrait mode                   | ![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-1ff159030cfb946fd5d1824d613c98355a128eff%2Feb976be4be65d5be73b0e643fa1526b7135b2104-788x272.png?alt=media)  |

## Show and hide the annotation toolbar

To create and set up an annotation toolbar, initialize an `AnnotationToolbar` instance and add it to your view hierarchy:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
let annotationToolbar = PTAnnotationToolbar(toolManager: toolManager)

// Set the current view controller as the annotation toolbar's delegate.
annotationToolbar.delegate = self;

self.view.addSubview(annotationToolbar)

// Position annotation toolbar in superview.
annotationToolbar.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activateConstraints([
    annotationToolbar.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
    annotationToolbar.widthAnchor.constraint(equalTo: self.view.widthAnchor),
    annotationToolbar.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor)
])

// Hide annotation toolbar by default.
annotationToolbar.isHidden = true
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
AnnotationToolbar *annotationToolbar = [[PTAnnotationToolbar alloc] initWithToolManager:toolManager];

// Set the current view controller as the annotation toolbar's delegate.
annotationToolbar.delegate = self;

[self.view addSubview:annotationToolbar];

// Position annotation toolbar in superview.
annotationToolbar.translatesAutoresizingMaskIntoConstraints = NO;

[NSLayoutConstraint activateConstraints:@[
   [annotationToolbar.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
   [annotationToolbar.widthAnchor constraintEqualToAnchor:self.view.widthAnchor],
   [annotationToolbar.topAnchor constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor],
 ]];

// Hide annotation toolbar by default.
annotationToolbar.hidden = YES;
```

{% endcode %}
{% endtab %}
{% endtabs %}

Then, you need to attach a [`ToolManager`](https://sdk.apryse.com/api/ios/Classes/PTToolManager.html) to the annotation toolbar so that the toolbar can change tools:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
annotationToolbar.toolManager = self.toolManager
// Show the annotation toolbar.
annotationToolbar.isHidden = false
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
annotationToolbar.toolManager = self.toolManager;
// Show the annotation toolbar.
annotationToolbar.hidden = NO;
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Customization

The [`PTAnnotationToolbar`](https://sdk.apryse.com/api/ios/Classes/PTAnnotationToolbar.html) class provides an API for specifying which tools are displayed in the toolbar when there is insufficient space to show them all. This is controlled by the [`precedenceArray`](https://sdk.apryse.com/api/ios/Classes/PTAnnotationToolbar.html#/c:objc\(cs\)PTAnnotationToolbar\(py\)precedenceArray)property, which is an array of [`PTAnnotBarButton`](https://sdk.apryse.com/api/ios/Enums/PTAnnotBarButton.html) items.

## Annotation toolbar delegate

The [`PTAnnotationToolbarDelegate`](https://sdk.apryse.com/api/ios/Protocols/PTAnnotationToolbarDelegate.html) protocol allows the adopting class (usually the containing view controller, as in [this guide](https://docs.apryse.com)) to be notified of annotation toolbar events and control the behavior of the toolbar. Since this protocol also conforms to the [`UIToolbarDelegate`](https://developer.apple.com/uikit/uitoolbardelegate/) protocol, the annotation toolbar's delegate can implement the `positionForBar:` method to indicate the toolbar position:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
func annotationToolbarDidCancel(_ annotationToolbar: PTAnnotationToolbar) {
	// Hide annotation toolbar when cancelled.
    annotationToolbar.isHidden = true
}
func position(for bar: UIBarPositioning) -> UIBarPosition {
	// The annotation toolbar is usually positioned at the top of its superview.
    return .top;
}
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
- (void)annotationToolbarDidCancel:(PTAnnotationToolbar *)annotationToolbar {
	// Hide annotation toolbar when cancelled.
	annotationToolbar.hidden = YES;
}
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
	// The annotation toolbar is usually positioned at the top of its superview.
	return UIBarPositionTop;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Edit annotations continuously

By default, the annotation toolbar returns to the pan tool after an annotation is created. If you prefer to stay in the same tool mode after an annotation is created, you should implement the `toolShouldGoBackToPan` method in your `AnnotationToolbarDelegate` adopting class:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
func toolShouldGoBack(toPan annotationToolbar: PTAnnotationToolbar) -> Bool {
    return false
}
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
- (BOOL)toolShouldGoBackToPan:(PTAnnotationToolbar *)annotationToolbar
{
	return NO;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

The annotation toolbar's behavior could also be handled within user settings by checking and returning the appropriate settings value in the method above.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/ios/annotation/annotation-toolbar-i.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
