PSPDFMenuItem
Objective-C
@interface PSPDFMenuItem : UIMenuItem
Swift
class MenuItem : 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. If no identifier is set, then title is required to be unique when converted to lowercase and non-ASCII characters are stripped, even when images are used.
-
Initialize
PSPDFMenuItem
with a block. Do not use this initializer unless your titles are unique when converted to lowercase and non-ASCII characters are stripped, because anidentifier
must be specified in that case. -
Initialize
PSPDFMenuItem
with a block and an non-localized unique identifier for later manipulation. -
Initialize
PSPDFMenuItem
with an image, a block and an non-localized unique 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 unique 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 (nonatomic, getter=isEnabled) 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 (nonatomic) BOOL shouldInvokeAutomatically;
Swift
var shouldInvokeAutomatically: Bool { get set }
-
Helper to identify the current action. Not localized.
Declaration
Objective-C
@property (nonatomic, copy, readonly, nullable) NSString *identifier;
Swift
var identifier: String? { get }
-
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 changetitle
. Useidentifier
to compare menu items instead. -
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.
-
Unavailable
Not the designated initializer
The parent designated initializer is not available in this subclass.
Declaration
Objective-C
- (nonnull instancetype)initWithTitle:(nonnull NSString *)title action:(nonnull SEL)action;
-
Undocumented