PSPDFAnnotationStyleManager
Objective-C
@protocol PSPDFAnnotationStyleManager
Swift
protocol AnnotationStyleManager
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 (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.
-
Keeps a list of style keys we want to listen to (like
color
orlineWidth
).Note
If you want to disable automatic style saving, set this to nil.Declaration
Objective-C
@property (copy, 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: Annotation.ToolVariantID) -> [AnnotationStyle]?
-
Adds a style on the key store.
Declaration
Objective-C
- (void)addStyle:(nonnull PSPDFAnnotationStyle *)style forKey:(nonnull PSPDFAnnotationStateVariantID)key;
Swift
func add(_ style: AnnotationStyle, forKey key: Annotation.ToolVariantID)
-
Removes a style from the key store.
Declaration
Objective-C
- (void)removeStyle:(nonnull PSPDFAnnotationStyle *)style forKey:(nonnull PSPDFAnnotationStateVariantID)key;
Swift
func remove(_ style: AnnotationStyle, forKey key: Annotation.ToolVariantID)
-
Get the last used style for
key
. UsesPSPDFAnnotationStyleTypeLastUsed
and callsstylesForKey:
.Declaration
Objective-C
- (nullable PSPDFAnnotationStyle *)lastUsedStyleForKey: (nonnull PSPDFAnnotationStateVariantID)key;
Swift
func lastUsedStyle(forKey key: Annotation.ToolVariantID) -> AnnotationStyle?
-
Convenience method. Will fetch the last used style for
key
and fetches thestyleProperty
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: Annotation.ToolVariantID) -> Any?
-
Convenience method. Will set the last used style for
key
andstyleProperty
.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. UsesPSPDFAnnotationStyleTypeLastUsed
and callsaddStyle: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: Annotation.ToolVariantID)
-
Returns default presets for a given
key
andtype
. Either presets set viasetDefaultPresets:forKey:type:
, or suitable internal defaults.See
presetsForKey:type:Note
The implementation should be thread safe.Declaration
Objective-C
- (nullable NSArray<id<PSPDFStylePreset>> *) defaultPresetsForKey:(nonnull PSPDFAnnotationStateVariantID)key type:(nonnull PSPDFAnnotationStyleType)type;
Swift
func defaultPresets(forKey key: Annotation.ToolVariantID, type: AnnotationStyle.Kind) -> [PSPDFStylePreset]?
-
Sets default presets for a given
key
andtype
. 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<id<PSPDFStylePreset>> *)presets forKey:(nonnull PSPDFAnnotationStateVariantID)key type:(nonnull PSPDFAnnotationStyleType)type;
Swift
func setDefaultPresets(_ presets: [PSPDFStylePreset]?, forKey key: Annotation.ToolVariantID, type: AnnotationStyle.Kind)
-
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<id<PSPDFStylePreset>> *) presetsForKey:(nonnull PSPDFAnnotationStateVariantID)key type:(nonnull PSPDFAnnotationStyleType)type;
Swift
func presets(forKey key: Annotation.ToolVariantID, type: AnnotationStyle.Kind) -> [PSPDFStylePreset]?
-
Updates the presets for the specified key and preset type.
@property presets An array of presets to save. They object must conform to
NSSecureCoding
. 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<id<PSPDFStylePreset>> *)presets forKey:(nonnull PSPDFAnnotationStateVariantID)key type:(nonnull PSPDFAnnotationStyleType)type;
Swift
func setPresets(_ presets: [PSPDFStylePreset]?, forKey key: Annotation.ToolVariantID, type: AnnotationStyle.Kind)
-
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: Annotation.ToolVariantID, type: AnnotationStyle.Kind) -> 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: Annotation.ToolVariantID, type: AnnotationStyle.Kind) -> Bool