> 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/basic-operations/basics/annot-style.md).

# Annotation style editor for Xamarin viewer

Learn how to edit annotation styles easily in Xamarin.iOS with PTAnnotStyleViewController. Customize colors, use presets, and manage annotation style changes effectively. Click to explore more! The Ap

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

The [`PTAnnotStyleViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Tools.PTAnnotStyleViewController.html) class shows annotation style properties in a half-modal bottom sheet, or optionally in a popover view on large-screened devices such as iPads or large iPhones in landscape mode. With this style editor, users can edit annotation styles easily with style presets as well as choosing their own colors through the color picker.

| Half-Modal Bottom Sheet                                                                                                                                                                                                                         | Popover                                                                                                                                                                                                                                          |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-cd42dab28a4dc1cabad94d038ab9fb70f3bac352%2Fb3f462d52707af13a45a2eef8b4b012f53ccca2c-750x1334.png?alt=media) | ![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-03edabb932ba17c38a3208560ca46213811df5f3%2Fb2daa892d227019fedd2fa988981c30961c188ef-1001x1334.png?alt=media) |

*The annotation style editor is part of the Tools library, so make sure you have* [*added the Tools library to your project*](/xamarin/ui-customization/setup.md)*.*

## Show/hide the style view controller

The annotation style state for the given annotation is managed by an [`PTAnnotStyle`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Tools.PTAnnotStyle.html) instance. To create and display a new annotation style view controller from another view controller, first create and supply an `PTAnnotStyle` instance to the `PTAnnotStyleViewController` initializer:

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

```csharp
// Initialize annot style with a Annot instance or PTAnnotType.
var annotStyle = new PTAnnotStyle(PTAnnotType.e_ptSquare);
var stylePicker = new PTAnnotStyleViewController(annotStyle);

// Save a strong reference to a half-modal presentation manager.
this.halfModalPresentationManager = new PTHalfModalPresentationManager();

// To show
this.PresentModalViewController(stylePicker, true);
```

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

`PTAnnotStyle` can also be initialized with an [`PTAnnotType`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.PTAnnotType.html), in which case the `PTAnnotStyle` will operate on the default style properties for that annotation type. (The default style properties are the ones that are used when a new annotation of that type is created.)

To hide the annotation style view controller programmatically, call `dismissViewControllerAnimated:completion` on either the presenting view controller or the annotation view controller itself.

### Present as a popover

To present the annotation style view controller in a popover, you should provide its presentation manager either:

* a [`sourceRect`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622324-sourcerect/) AND
* a [`sourceView`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622313-sourceview/)

OR

* a [`barButtonItem`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622314-barbuttonitem/)

This will define the anchor point of the popover view. See the code sample above for an example of how to do this using an annotation's rect as the `sourceRect`, and the `PDFViewCtrl` as the `sourceView`.

## Save annotation style changes

The annotation view controller does not commit the annotation style changes back to the annotation unless explicitly told to do so. To commit the annotation style changes, implement the [`annotStyleViewController:didCommitStyle:`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Tools.PTAnnotStyleViewController.html#pdftron_PDF_Tools_PTAnnotStyleViewController_DidCommitStyle) and/or [`annotStyleViewController:didChangeStyle:`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Tools.PTAnnotStyleViewController.html#pdftron_PDF_Tools_PTAnnotStyleViewController_DidChangeStyle) methods of the `AnnotStyleViewControllerDelegate` protocol:

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

```csharp
stylePicker.DidChangeStyle += (sender, e) =>
{
  
};
stylePicker.DidCommitStyle += (sender, e) =>
{
  
};
```

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

The `annotStyleViewController:didCommitStyle:` method is called when the annotation style view controller is dismissed either by the user pressing the 'Done' button or de-selecting the current annotation. The optional `annotStyleViewController:didChangeStyle:` method is called immediately after any annotation style property is changed by the user. For slider-controlled properties (thickness, opacity, etc.), an event notifying of the change is triggered when the user releases the slider control.

The `saveAnnotStyleChanges:` helper method used above can be defined as follows:

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

```csharp
void SaveAnnotStyleChanges(PTAnnotStyle annotStyle) {
    var annot = TypeConvertHelper.ConvAnnotToManaged(annotStyle.Annot);
    // Ensure annotation being edited is still valid.
    if (currentAnnotation != annot || !annot.IsValid())
    {
        return;
    }

    try
    {
        pdfViewCtrl.DocLock(true);
        annotStyle.SaveChanges();
        currentAnnotation.RefreshAppearance();
        pdfViewCtrl.UpdateWithAnnot(currentAnnotation, annotationPageNumber);
        annotStyle.SetCurrentValuesAsDefaults();
    }
    catch (Exception ex)
    {

    }
    finally
    {
        pdfViewCtrl.DocUnlock();
    }
}
```

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

The call to `setCurrentValuesAsDefaults` in the code above is not necessary if the `saveValuesAsDefaults` property (enabled by default) is set, as in this case `saveChanges` will automatically save the style as the new default style.

The sequence of document locking and annotation updates shown here is used throughout the Tools framework. For more information on document locking please see the [dedicated guide ](/xamarin/basic-operations/lock.md).


---

# 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/xamarin/basic-operations/basics/annot-style.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.
