---
title: "Customizing Apple Pencil annotations in iOS PDF viewer | Nutrient"
canonical_url: "https://www.nutrient.io/guides/ios/annotations/apple-pencil/"
md_url: "https://www.nutrient.io/guides/ios/annotations/apple-pencil.md"
last_updated: "2026-05-30T02:20:01.301Z"
description: "Nutrient iOS SDK offers first-class support for Apple Pencil. There are a few places where you can customize how Apple Pencil interacts with Nutrient:."
---

# Customizing Apple Pencil annotations on iOS

Nutrient iOS SDK offers first-class support for Apple Pencil. There are a few places where you can customize how Apple Pencil interacts with Nutrient:

- [`ApplePencilManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/applepencilmanager) tracks the detection status of Apple Pencil and whether or not it should be used for any touch interaction.

- [`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager) manages how touch events are handled. See the [Annotation State Manager](https://www.nutrient.io/../../annotations/annotation-state-manager) guide to learn more.

- [`AnnotationToolbar`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationtoolbar) can show a button that lets users enable and disable the use of Apple Pencil using [`ApplePencilManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/applepencilmanager).

- For double-tap actions from `UIPencilInteraction`, see our [Apple Pencil Double-Tap Actions](https://www.nutrient.io/../../annotations/apple-pencil-double-tap-actions) guide.

## Default behavior

The default flow of using Apple Pencil with Nutrient is as follows.

Users can select an annotation tool from [`AnnotationToolbar`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationtoolbar). Whenever a touch from Apple Pencil is detected, [`ApplePencilManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/applepencilmanager) enables Apple Pencil. This can be disabled by setting [`ApplePencilManager.enableOnDetection`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/applepencilmanager/enableondetection) to `false`.

[`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager) decides whether or not to allow direct (finger) touches to create annotations depending on whether or not Apple Pencil has been enabled according to [`ApplePencilManager.enabled`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/applepencilmanager/enabled). This means that after the user starts annotating with Apple Pencil, direct touches stop creating annotations so that the user can scroll and tap with fingers as normal. This can be changed by setting the [`stylusMode`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager/stylusmode) property.

After detecting a touch from Apple Pencil the first time, [`AnnotationToolbar`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationtoolbar) shows a stylus button that displays the stylus connection status. This can be disabled by setting [`showsApplePencilButtonAutomatically`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationtoolbar/showsapplepencilbuttonautomatically) to `false`. When this button is tapped, a new [`ApplePencilController`] initialized using [`SDK.shared.applePencilManager`] is shown, allowing the user to stop using Apple Pencil if they prefer to annotate using fingers.

## Apple Pencil availability

There is no simple way to know whether a device supports Apple Pencil, whether the user has one, and if it is currently connected. All an app knows is that if it receives a touch event of type `UITouch.TouchType.pencil`, then an Apple Pencil was connected at that time.

Nutrient models the availability of Apple Pencil with the [`ApplePencilManager.detected`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/applepencilmanager/detected) property. Nutrient sets this to `true` whenever detecting a touch of type `UITouch.TouchType.pencil` on a page view. If your app detects a touch from Apple Pencil elsewhere, you can set this property so that Nutrient can show the stylus button in the annotation toolbar as soon as it appears:

### SWIFT

```swift

let touch: UITouch =...
if touch.type ==.stylus {
    SDK.shared.applePencilManager.detected = true
}

```

### OBJECTIVE-C

```objc

UITouch *touch =...
if (touch.type == UITouchTypeStylus) {
    PSPDFKitGlobal.sharedInstance.applePencilManager.detected = YES;
}

```

Every time this property is set, the [`ApplePencilManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/applepencilmanager) posts [`PSPDFApplePencilDetectedNotification`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/foundation/nsnotification/name/pspdfapplepencildetected). Note that this happens even if the value does not change.

To only show a UI element if Apple Pencil is definitely available so that it does not clutter the screen otherwise, use the following:

### SWIFT

```swift

func someSetupMethod() {
    NotificationCenter.default.addObserver(self, selector: #selector(stylusDetectionChanged(notification:)), name:.PSPDFApplePencilDetected, object: ApplePencilManager.self)

}

@objc func stylusDetectionChanged(notification: Notification) {
    self.showsSomeStylusUI = SDK.shared.applePencilManager.detected
}

```

### OBJECTIVE-C

```objc

- (void)someSetupMethod {
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(stylusDetectionChanged:) name:PSPDFApplePencilDetectedNotification object:PSPDFApplePencilManager.class];
}

- (void)stylusDetectionChanged:(NSNotification *)notification {
   self.showsSomeStylusUI = PSPDFKitGlobal.sharedInstance.applePencilManager.detected;
}

```

### Making Apple Pencil available across your application

To get the absolute best entry point for automatic Apple Pencil detection, subclass `UIApplication` and override `sendEvent`:

### SWIFT

```swift

class Application: UIApplication {
    override func sendEvent(_ event: UIEvent) {
        super.sendEvent(event)
        let pencilManager = SDK.shared.applePencilManager
        guard applePencilManager.detected == false, event.type ==.touches, let touches = event.allTouches else {
            return
        }
        if (touches.contains { $0.type ==.stylus && $0.phase ==.began }) {
            applePencilManager.detected = true
        }
    }
}

```

Then make sure that the application is loaded from UIKit when it starts up via writing `main.swift`:

```swift

UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, NSStringFromClass(Application.self), NSStringFromClass(AppDelegate.self))

```

The [syntax for subclassing `UIApplication` in Objective-C is slightly different, but accomplishing this is also possible](https://stackoverflow.com/questions/1399202/how-to-subclass-uiapplication).

## Always create a particular annotation type with Apple Pencil

You can ensure touches with Apple Pencil always create a particular annotation type, which would be a good fit if your app does not show the annotation toolbar and focuses on one type of annotation. For example, you could set Apple Pencil touches to always draw ink. Alternatively, you could set Apple Pencil to always highlight text similar to how it’s done in Books, which you can see in the Books-like highlighting example, (`PSCBooksHighlightingExample`).

First set up the annotation state manager:

### SWIFT

```swift

let annotationStateManager = pdfController.annotationStateManager
annotationStateManager.state =.ink
annotationStateManager.stylusMode =.stylus

```

### OBJECTIVE-C

```objc

PSPDFAnnotationStateManager *annotationStateManager = pdfController.annotationStateManager;
annotationStateManager.state = PSPDFAnnotationStringInk;
annotationStateManager.stylusMode = PSPDFAnnotationStateManagerStylusModeStylus;

```

Make sure the user can’t change the state by disabling the annotation toolbar by removing the `annotationButtonItem`, which is included by default, and disabling the menu shown on long press:

### SWIFT

```swift

pdfController.navigationItem.setRightBarButtonItems([pdfController.thumbnailsButtonItem, pdfController.activityButtonItem /* etc. as long as this excludes annotationButtonItem */], for:.document, animated: false)
pdfController.updateConfiguration { builder in
    builder.isCreateAnnotationMenuEnabled = false
}

```

### OBJECTIVE-C

```objc

[pdfController.navigationItem setRightBarButtonItems:@[pdfController.thumbnailsButtonItem, pdfController.activityButtonItem /* etc. as long as this excludes annotationButtonItem */] forViewMode:PSPDFViewModeDocument animated:NO];
[pdfController updateConfigurationWithBuilder:^(PSPDFConfigurationBuilder *builder) {
    builder.createAnnotationMenuEnabled = NO;
}];

```
---

## Related pages

- [Support for Apple Pencil double tap on iOS](/guides/ios/annotations/apple-pencil-double-tap-actions.md)

