I have successfully been able to add a custom UIMenuItem to the Copy & Paste menu in my iPhone app, and even subclassed UITextView to get r
If the question is still relevant then you could use the UIMenuControllerWillShowMenuNotification
or the UIMenuControllerDidShowMenuNotification
notification.
See the documentation here.
Code sample:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willShowMenu:) name:UIMenuControllerWillShowMenuNotification object:nil];
At startup somewhere:
UIMenuItem *testMenuItem = [[UIMenuItem alloc] initWithTitle:@"Test" action:@selector(test:)];
[UIMenuController sharedMenuController].menuItems = [NSArray arrayWithObject:testMenuItem];
[testMenuItem release];
And in your UITextView
or UITextField
subclass:
@implementation MyTextView
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(test:)) {
// Return YES only if it's possible to perform the action at this time
return YES;
}
return [super canPerformAction:action withSender:sender];
}
- (void)test:(id)sender {
// Perform the action here
}
@end