Customizing Color Presets

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

The color presets are managed by the global PSPDFAnnotationStyleManager object (found under PSPDFKit.sharedInstance.styleManager).

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

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

Copy
1
2
3
4
5
6
7
8
let presets = [
    PSPDFColorPreset(color: UIColor.black),
    PSPDFColorPreset(color: UIColor.red),
    PSPDFColorPreset(color: UIColor.green),
    PSPDFColorPreset(color: UIColor.blue)
]
let styleManager = PSPDFKit.sharedInstance.styleManager
styleManager.setPresets(presets, forKey: .line, type: PSPDFStyleManagerColorPresetKey)
Copy
1
2
3
4
5
6
NSArray<PSPDFColorPreset *> *presets = @[[PSPDFColorPreset presetWithColor:UIColor.blackColor],
                                         [PSPDFColorPreset presetWithColor:UIColor.redColor],
                                         [PSPDFColorPreset presetWithColor:UIColor.greenColor],
                                         [PSPDFColorPreset presetWithColor:UIColor.blueColor]];
PSPDFAnnotationStyleManager *styleManager = PSPDFKit.sharedInstance.styleManager;
[styleManager setPresets:presets forKey:PSPDFAnnotationStringLine type:PSPDFStyleManagerColorPresetKey];

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