> 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/xamarin/guides/viewer-components/annotation-toolbar-i.md).

# Customize annotation toolbar in Xamarin viewer

Learn how to create and customize an annotation toolbar in Xamarin.iOS. Add various annotation creation tools and control their behavior with PTAnnotationToolbar class. Customize tool display and dele

{% hint style="info" %}
**This tutorial only applies to Xamarin.iOS. See Xamarin.Android equivalent here .**
{% endhint %}

The [`PTAnnotationToolbar`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.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://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%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](/xamarin/annotation/config-annot-tools.md#ios).

{% 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://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-2d0f33e6431a2528823efc9022b984e0820b010d%2Fdecc5c514a4f4705a4d845543872a2965f9f5e3c-1466x184.png?alt=media) |
| Small devices in portrait mode                   | ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%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="C#" %}
{% code lineNumbers="true" %}

```csharp
var annotationToolbar = new pdftron.PDF.Controls.PTAnnotationToolbar(mToolManager);
annotationToolbar.AnnotationToolbarDidCancel += (sender, e) =>
{
    annotationToolbar.Hidden = true;
};
View.AddSubview(annotationToolbar);

// position annotation toolbar
annotationToolbar.TranslatesAutoresizingMaskIntoConstraints = false;
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
    annotationToolbar.LeadingAnchor.ConstraintEqualTo(this.View.LeadingAnchor),
    annotationToolbar.WidthAnchor.ConstraintEqualTo(this.View.WidthAnchor),
    annotationToolbar.TopAnchor.ConstraintEqualTo(this.View.LayoutMarginsGuide.TopAnchor)
});

// hide annotation toolbar by default
annotationToolbar.Hidden = true;
```

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

To show:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
// Show the annotation toolbar.
annotationToolbar.Hidden = false;
```

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

## Customization

The [`PTAnnotationToolbar`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.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/xamarinios/tools/api/pdftron.PDF.Controls.PTAnnotationToolbar.html#pdftron_PDF_Controls_PTAnnotationToolbar_PrecedenceArray) property.

## Annotation toolbar delegate

The [`PTAnnotationToolbarDelegate`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.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.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
annotationToolbar.AnnotationToolbarDidCancel += (sender, e) =>
{
    annotationToolbar.Hidden = true;
}
```

{% 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="C#" %}
{% code lineNumbers="true" %}

```csharp
mAnnotationToolbar.ToolShouldGoBackToPan = (annotationToolbar) =>
{
    return false;
};
```

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/xamarin/guides/viewer-components/annotation-toolbar-i.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
