2

How to remove default menu items like copy, past, SelectAll when i select WebView content. How to put custom actions in middle of default menu items.Which items i'm putting these are showing in last, i want to my custom actions from starting. I'm using below code in view didAppear method.

UIMenuItem *customMenuItem1=[[UIMenuItem alloc] initWithTitle:@"Highlight" action:@selector(customAction1:)];
UIMenuItem *customMenuItem2=[[UIMenuItem alloc] initWithTitle:@"UnHighlight" action:@selector(UnHighlighted:)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:customMenuItem1,customMenuItem2,nil]];
[UIMenuController sharedMenuController].menuVisible=YES;

Please help me.

Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144

1 Answers1

0

enter image description hereAs answered here showing custom menu on selection in UIWebView in iphone

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.google.com"]]];
    self.webview.backgroundColor = [UIColor blueColor];
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIMenuItem *customMenuItem1 = [[UIMenuItem alloc] initWithTitle:@"Custom 1" action:@selector(customAction1:)];
    UIMenuItem *customMenuItem2 = [[UIMenuItem alloc] initWithTitle:@"Custom 2" action:@selector(customAction2:)];
    [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:customMenuItem1, customMenuItem2, nil]];

}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [[UIMenuController sharedMenuController] setMenuItems:nil];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (self.webview.superview != nil)// && ![urlTextField isFirstResponder])
    {
        if (action == @selector(customAction1:) || action == @selector(customAction2:))
        {
            return YES;
        }
    }
    return [super canPerformAction:action withSender:sender];
}
-(void)customAction1:(UIMenuItem*)item
{}
-(void)customAction2:(UIMenuItem*)item
{}
Community
  • 1
  • 1
Amit Tandel
  • 883
  • 7
  • 16