弹出菜单的使用

- (void)viewDidLoad
{
    [super viewDidLoad];
    _button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _button.frame = CGRectMake(0, 300, 320, 30);
    [_button setTitle:NSLocalizedString(@"Press Me", nil) forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(pressme:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_button];
}
- (void)pressme:(id)sender
{
    UIMenuItem *flag = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(flag:)];
    UIMenuItem *approve = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(approve:)];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    [menu setMenuItems:[NSArray arrayWithObjects:flag, approve, nil]];
    [menu setTargetRect:[sender frame] inView:self.view];
    [menu setMenuVisible:YES animated:YES];
}
- (BOOL)canBecomeFirstResponder
{
    return YES;
}

 

你可能感兴趣的:(使用)