Dev:ActionMenu

ActionMenu is an extension that adds extra options to the menu that pops up when you select text or tap-and-hold an item (such as an image or a table cell).

Developers can integrate with it (by making a plugin) to add their own custom options to these menus.

How to use this library
Headers are available from ActionMenu.h. If using Theos, place the headers in.

The project type should be a library.

Makefile
Add to your Makefile:


 * to the  variable.
 * to the  variable.
 * to the  variable.

Packaging
Add to your package's control file:


 * to the  field.

Creating an Action Menu Plugin
We implement a category of the UIResponder class which will be loaded by Action Menu. Action Menu also provides us with easy methods to register our new UIMenuController item.

AMExample.h
We will first create our header file which will not have more than the category interface:

AMExample.m
We are going to implement the methods and then our category in the .m implementation file.

We can use the NSObject's +(void)load method (which will be executed earlier than any other method) to initialize and create our UIMenuController item.

Now we have to implement the canPerformAction and performMyAction method. The canPerformAction checks for the length of the selected text and checks wether it is 0 or higher. It can only perform (return TRUE) if the selected text is longer than 0 characters.

Now we have to implement the canPerformAction and performMyAction method to complete this plugin:

And in our performMyAction method we show an UIAlertView:

To sum it up, +(void)load registers our Action Menu Item to be shown in the UIMenuController, - (BOOL)canPerformAction checks if there is any selected text, and - (void)performMyAction will run our code when the menu item is selected.

This is everything you need to know for your first Action Menu Plugin. All you need to do is change the actions that take place in the performMyAction method and you can customize your plugin.