2

I am creating an app that contain UITextView that contain large amount of text. and when i double tap any text than its default behavior will happen and show UIMenuController. like this,

enter image description here

But i want to display custom popup instead of UIMenuController like this,

enter image description here

How can i do this?

UPDATE

Which method will called when this UIMenuController open?

Community
  • 1
  • 1
  • see this: http://stackoverflow.com/questions/3267296/how-do-i-add-a-custom-uimenuitem-to-the-uimenucontroller-in-a-uitextview and http://stackoverflow.com/questions/3537795/uimenucontroller-custom-items – DharaParekh Jul 02 '13 at 11:49
  • @DharaParekh As i said i dont want to add any more option in UIMenucontroller but instead of it i want to replace it with my pop up –  Jul 02 '13 at 12:06

1 Answers1

0

Check this accepted answer to this question.

You can subclass UITextField and override the below method to disable whichever action you want :

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{
    if (action == @selector(paste:))
    {
        return NO;
    }
    else if (action == @selector(cut:))
    {
        return NO; 
    }
    else if (action == @selector(copy:))
    {
        return NO;
    }
     ... //etc etc

    return [super canPerformAction:action withSender:sender];
}

and display your own using the following code:

UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setTargetRect:textField.frame inView:textField.superview];
[menu setMenuItems:[NSArray arrayWithObjects:
                            [[UIMenuItem alloc] initWithTitle:@"Test" action:@selector(test)],
                            nil]];
[menu setMenuVisible:YES animated:YES];

and in the canPeformAction:withSender: method you can return YES for the selector Test.

Community
  • 1
  • 1
Rakesh
  • 3,370
  • 2
  • 23
  • 41