How to add context menu to app in IOS

Whatsapp screenshot

I would like to know how to implement this "context menu" with action buttons like the ones that appear in whatsapp and other applications when clicking on a message.

Many thanks.

+4


source to share


1 answer


This is UIMenuController

. I'm not good with Swift. For Swift, please check this link. The purpose of the C code looks like this:



- (void)showMenu
{
    UIMenuController *menu = [UIMenuController sharedMenuController];
    menu.menuItems = @[
       [[UIMenuItem alloc] initWithTitle:@"Title1" action:@selector(MyAction1)],
       [[UIMenuItem alloc] initWithTitle:@"Title2" action:@selector(MyAction2)],
       [[UIMenuItem alloc] initWithTitle:@"Title3" action:@selector(MyAction)]];
    [menu setTargetRect:self.bounds inView:self];
    [menu setMenuVisible:YES animated:YES];
}

      

+6


source







All Articles