PSPDFAnnotationStyleManager

@protocol PSPDFAnnotationStyleManager

The annnotation style manager will save UI-specific properties for annotations and apply them after creation.

It also offers a selection of user-defined styles. There are three categories: Last used, key-specific and generic styles.

  • When annotations are changed and this is enabled, the defaults are updated accordingly. This defaults to YES.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        BOOL shouldUpdateDefaultsForAnnotationChanges;

    Swift

    var shouldUpdateDefaultsForAnnotationChanges: Bool { get set }
  • Set default annotation styles. This is the perfect place to set your own default annotation styles.

    Declaration

    Objective-C

    - (void)setupDefaultStylesIfNeeded;

    Swift

    func setupDefaultStylesIfNeeded()
  • Keeps a list of style keys we want to listen to (like color or lineWidth).

    Note

    If you want to disable automatic style saving, set this to nil.

    Declaration

    Objective-C

    @property (readwrite, copy, atomic, nullable) NSSet<NSString *> *styleKeys;

    Swift

    var styleKeys: Set<String>? { get set }
  • Returns the annotation styles, for the given key. Might return nil if there isn’t anything saved yet.

    Declaration

    Objective-C

    - (nullable NSArray<PSPDFAnnotationStyle *> *)stylesForKey:
        (nonnull PSPDFAnnotationStateVariantID)key;

    Swift

    func styles(forKey key: AnnotationStateVariantID) -> [PSPDFAnnotationStyle]?
  • Adds a style on the key store.

    Declaration

    Objective-C

    - (void)addStyle:(nonnull PSPDFAnnotationStyle *)style
              forKey:(nonnull PSPDFAnnotationStateVariantID)key;

    Swift

    func add(_ style: PSPDFAnnotationStyle, forKey key: AnnotationStateVariantID)
  • Removes a style from the key store.

    Declaration

    Objective-C

    - (void)removeStyle:(nonnull PSPDFAnnotationStyle *)style
                 forKey:(nonnull PSPDFAnnotationStateVariantID)key;

    Swift

    func remove(_ style: PSPDFAnnotationStyle, forKey key: AnnotationStateVariantID)
  • Get the last used style for key. Uses PSPDFAnnotationStyleTypeLastUsed and calls stylesForKey:.

    Declaration

    Objective-C

    - (nullable PSPDFAnnotationStyle *)lastUsedStyleForKey:
        (nonnull PSPDFAnnotationStateVariantID)key;

    Swift

    func lastUsedStyle(forKey key: AnnotationStateVariantID) -> PSPDFAnnotationStyle?
  • Convenience method. Will fetch the last used style for key and fetches the styleProperty for it. Might return nil.

    Declaration

    Objective-C

    - (nullable id)lastUsedProperty:(nonnull NSString *)styleProperty
                             forKey:(nonnull PSPDFAnnotationStateVariantID)key;

    Swift

    func lastUsedProperty(_ styleProperty: String, forKey key: AnnotationStateVariantID) -> Any?
  • Convenience method. Will set the last used style for key and styleProperty. value might be a boxed CGFloat, color or whatever matches the property. styleProperty is the NSString-name for the property (e.g. NSStringFromSelector(@ selector(fontSize)) key is a annotation string, e.g. PSPDFAnnotationStringFreeText. Uses PSPDFAnnotationStyleTypeLastUsed and calls addStyle:forKey.

    Declaration

    Objective-C

    - (void)setLastUsedValue:(nullable id)value
                 forProperty:(nonnull NSString *)styleProperty
                      forKey:(nonnull PSPDFAnnotationStateVariantID)key;

    Swift

    func setLastUsedValue(_ value: Any?, forProperty styleProperty: String, forKey key: AnnotationStateVariantID)
  • Returns default presets for a given key and type. Either presets set via setDefaultPresets:forKey:type:, or suitable internal defaults.

    See

    presetsForKey:type:

    Note

    The implementation should be thread safe.

    Declaration

    Objective-C

    - (nullable NSArray<__kindof PSPDFModel *> *)
    defaultPresetsForKey:(nonnull PSPDFAnnotationStateVariantID)key
                    type:(nonnull PSPDFAnnotationStyleType)type;

    Swift

    func defaultPresets(forKey key: AnnotationStateVariantID, type: AnnotationStyleType) -> [PSPDFModel]?
  • Sets default presets for a given key and type. The set default presets shoiuld be stored in memory only and set on every app restart.

    See

    setPresets:forKey:type:

    Note

    The implementation should be thread safe.

    Declaration

    Objective-C

    - (void)setDefaultPresets:(nullable NSArray<__kindof PSPDFModel *> *)presets
                       forKey:(nonnull PSPDFAnnotationStateVariantID)key
                         type:(nonnull PSPDFAnnotationStyleType)type;

    Swift

    func setDefaultPresets(_ presets: [PSPDFModel]?, forKey key: AnnotationStateVariantID, type: AnnotationStyleType)
  • Get the color presets for a specified key and preset type. Returns the set presets or appropriate default presets if no custom presets were set. Returns an array of objects corresponding to the preset type (e.g, PSPDFColorPreset).

    @property key The annotation string, e.g. PSPDFAnnotationStringFreeText. @property type The preset type, e.g. PSPDFAnnotationStyleTypeColorPreset (see PSPDFAnnotationStyleManager.h).

    Declaration

    Objective-C

    - (nullable NSArray<__kindof PSPDFModel *> *)
    presetsForKey:(nonnull PSPDFAnnotationStateVariantID)key
             type:(nonnull PSPDFAnnotationStyleType)type;

    Swift

    func presets(forKey key: AnnotationStateVariantID, type: AnnotationStyleType) -> [PSPDFModel]?
  • Updates the presets for the specified key and preset type.

    @property presets An array of presets to save. They object must conform to NSCoding. Setting nil removes the presets from storage and reverts to the default presets (if set). @property key The annotation string, e.g. PSPDFAnnotationStringFreeText. @property type The preset type, e.g. PSPDFAnnotationStyleTypeColorPreset (see PSPDFAnnotationStyleManager.h).

    Declaration

    Objective-C

    - (void)setPresets:(nullable NSArray<__kindof PSPDFModel *> *)presets
                forKey:(nonnull PSPDFAnnotationStateVariantID)key
                  type:(nonnull PSPDFAnnotationStyleType)type;

    Swift

    func setPresets(_ presets: [PSPDFModel]?, forKey key: AnnotationStateVariantID, type: AnnotationStyleType)
  • Checks if the preset at the given index differs from its default value.

    @property presets Index of preset in the preset array. @property key The annotation string, e.g. PSPDFAnnotationStringFreeText. @property type The preset type, e.g. PSPDFAnnotationStyleTypeColorPreset (see PSPDFAnnotationStyleManager.h).

    Declaration

    Objective-C

    - (BOOL)isPresetModifiedAtIndex:(NSUInteger)index
                             forKey:(nonnull PSPDFAnnotationStateVariantID)key
                               type:(nonnull PSPDFAnnotationStyleType)type;

    Swift

    func isPresetModified(at index: UInt, forKey key: AnnotationStateVariantID, type: AnnotationStyleType) -> Bool
  • Resets the preset at the given index to its default value.

    @property presets Index of preset in the preset array. @property key The annotation string, e.g. PSPDFAnnotationStringFreeText. @property type The preset type, e.g. PSPDFAnnotationStyleTypeColorPreset (see PSPDFAnnotationStyleManager.h).

    Declaration

    Objective-C

    - (BOOL)resetPresetAtIndex:(NSUInteger)idx
                        forKey:(nonnull PSPDFAnnotationStateVariantID)key
                          type:(nonnull PSPDFAnnotationStyleType)type;

    Swift

    func resetPreset(at idx: UInt, forKey key: AnnotationStateVariantID, type: AnnotationStyleType) -> Bool