PSPDFMenuItem


@interface PSPDFMenuItem : UIMenuItem

This subclass adds support for a block-based action on UIMenuItem. If you are as annoyed about the missing target/action pattern, you will love this.

If you use PSPDFMenuItem with the classic initWithTitle:selector: initializer, this will work and be handled just like a regular UIMenuItem.

Warning

By design, PSPDFMenuItem will only work with different title names. Title is required to be > 0 and unique, even when images are used. If you also use identifier then it is sufficient for the combined string to be unique.
  • Initialize PSPDFMenuItem with a block.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTitle:(nonnull NSString *)title
                                    block:(nonnull void (^)(void))block;

    Swift

    convenience init(title: String, block: @escaping () -> Void)
  • Initialize PSPDFMenuItem with a block and an non-localized identifier for later manipulation.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTitle:(nonnull NSString *)title
                                    block:(nonnull void (^)(void))block
                               identifier:(nullable NSString *)identifier;

    Swift

    convenience init(title: String, block: @escaping () -> Void, identifier: String?)
  • Initialize PSPDFMenuItem with an image, a block and an non-localized identifier for later manipulation. Will not allow image colors.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTitle:(nonnull NSString *)title
                                    image:(nullable UIImage *)image
                                    block:(nonnull void (^)(void))block
                               identifier:(nullable NSString *)identifier;

    Swift

    convenience init(title: String, image: UIImage?, block: @escaping () -> Void, identifier: String?)
  • Initialize PSPDFMenuItem with an image, a block and an non-localized identifier for later manipulation.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTitle:(nonnull NSString *)title
                                    image:(nullable UIImage *)image
                                    block:(nonnull void (^)(void))block
                               identifier:(nullable NSString *)identifier
                         allowImageColors:(BOOL)allowImageColors;

    Swift

    init(title: String, image: UIImage?, block: @escaping () -> Void, identifier: String?, allowImageColors: Bool)
  • Menu item can be enabled/disabled. (disable simply hides it from the UIMenuController)

    Declaration

    Objective-C

    @property (getter=isEnabled, assign, readwrite, nonatomic) BOOL enabled;

    Swift

    var isEnabled: Bool { get set }
  • If this is set to YES, we will invoke the menu item automatically, instead of presenting it.

    Declaration

    Objective-C

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

    Swift

    var shouldInvokeAutomatically: Bool { get set }
  • Helper to identify the current action. Not localized.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSString *identifier;

    Swift

    var identifier: String? { get set }
  • Image of the menu item. 24x24px is a good size. Images larger than 32x32px are automatically resized.

    If set the image will hide the title. This is prefixed to make sure it will work even when Apple decides to add support for images in future releases. - warning: Due to implementation details, this will actually change title. Use identifier to compare menu items instead.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) UIImage *ps_image;

    Swift

    var ps_image: UIImage? { get set }
  • Undocumented

    Declaration

    Objective-C

    
    @interface PSPDFMenuItem : UIMenuItem
  • Installs the menu handler. Needs to be called once per class. (A good place is the +load method)

    Following methods will be swizzled: - canBecomeFirstResponder (if object doesn’t already return YES) - canPerformAction:withSender: - methodSignatureForSelector: - forwardInvocation:

    The original implementation will be called if the PSPDFMenuItem selector is not detected.

    Declaration

    Objective-C

    + (void)installMenuHandlerForObject:(nonnull id)object;

    Swift

    class func installMenuHandler(for object: Any)

    Parameters

    object

    can be an instance or a class.

  • Undocumented

    Declaration

    Objective-C

    
    @interface PSPDFMenuItem : UIMenuItem
  • The parent designated initializer is not available in this subclass.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTitle:(nonnull NSString *)title
                                   action:(nonnull SEL)action;