Customizing Color Presets on iOS

In some cases, you might want to customize the default set of color presets shown in the annotation style inspector (AnnotationStyleViewController).

The color presets are managed by the global AnnotationStyleManager object (found under SDK.shared.styleManager).

The easiest way to customize the default presets while leaving other annotation style-related functionality intact is to set the new presets using AnnotationStyleManager.

Here is an example implementation that customizes the default colors for line annotations. All we have to do is set our own array of ColorPreset objects:

let presets = [
let styleManager = SDK.shared.styleManager
let key = Annotation.ToolVariantID(tool: .line)
styleManager.setPresets(presets, forKey: key, type: .colorPreset)
NSArray<PSPDFColorPreset *> *presets = @[[PSPDFColorPreset presetWithColor:UIColor.blackColor],
                                         [PSPDFColorPreset presetWithColor:UIColor.redColor],
                                         [PSPDFColorPreset presetWithColor:UIColor.greenColor],
                                         [PSPDFColorPreset presetWithColor:UIColor.blueColor]];
PSPDFDefaultAnnotationStyleManager *styleManager = (PSPDFDefaultAnnotationStyleManager *)PSPDFKitGlobal.sharedInstance.styleManager;
PSPDFAnnotationStateVariantID key = PSPDFAnnotationStateVariantIDMake(PSPDFAnnotationStringLine, nil);
[styleManager setPresets:presets forKey:key type:PSPDFAnnotationStyleTypeColorPreset];

Take a look at PresetCustomizationExample.swift in the PSPDFKit Catalog for a complete example.