iOS14加入的新菜单UIMenu

  1. 导航栏添加
  UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone menu:[self menu]];
  self.navigationItem.leftBarButtonItem = leftItem;
   
  2. 普通button添加
  UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
  button.menu = [self menu];
  button.showsMenuAsPrimaryAction = YES;
  [self.view addSubview:button];
- (UIMenu *)menu
{
    UIAction *action1 = [UIAction actionWithTitle:@"添加" image:ImageSystem(@"folder", 20) identifier:@"tianjia" handler:^(UIAction *action) {
        NSLog(@"添加");
    }];
    UIAction *action2 = [UIAction actionWithTitle:@"删除" image:ImageSystem(@"trash", 20) identifier:@"shanchu" handler:^(UIAction *action) {
        NSLog(@"删除");
    }];
    return [UIMenu menuWithChildren:@[action1, action2]];
}
效果

你可能感兴趣的:(iOS14加入的新菜单UIMenu)