You can manually display the Cut / Copy / Paste menu using the UIMenuController class . For example, the following code displays a menu focused on your image:
[self becomeFirstResponder]; UIMenuController *copyMenuController = [UIMenuController sharedMenuController]; [copyMenuController setTargetRect:image.frame inView:self.view]; [copyMenuController setMenuVisible:YES animated:YES];
It is assumed that this code will be implemented in the UIViewController for the view on which your image is placed.
To enable various menu items, you also need to implement several delegate methods in your controller:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(cut:)) return NO; else if (action == @selector(copy:)) return YES; else if (action == @selector(paste:)) return NO; else if (action == @selector(select:) || action == @selector(selectAll:)) return NO; else return [super canPerformAction:action withSender:sender]; } - (BOOL)canBecomeFirstResponder { return YES; }
In this case, only the "Copy" option will be enabled. You will also need to implement the appropriate -copy method: to handle what happens when the user selects this menu item.
Brad larson
source share