自定义拷贝粘贴窗口




1)、重写canBecomeFirstResponder方法

- (BOOL)canBecomeFirstResponder{
  [super canBecomeFirstResponder];
  return YES;
}


2)、创建自定义UIMenuController

  UIMenuItem *share = [[UIMenuItem alloc]initWithTitle:@"分享" action:@selector(share:)];
    UIMenuItem *email =[[UIMenuItem alloc] initWithTitle:@"邮件"action:@selector(email:)];
    UIMenuItem *print =[[UIMenuItem alloc] initWithTitle:@"打印"action:@selector(print:)];

    UIMenuController *menu =[UIMenuController sharedMenuController];
    [menu setMenuItems:[NSArrayarrayWithObjects:share, email,print, nil]];
    [menu setTargetRect:self.frameinView:self.superview];
    [menu setMenuVisible:YESanimated:YES];

(3)、判断显示哪个menu

- (BOOL)canPerformAction:(SEL)actionwithSender:(id)sender
{
  [super canPerformAction:actionwithSender:sender];
 
  if ( action == @selector(share:) || action ==@selector(email:) || action == @selector(print:))
  {
      returnYES;    
  }
  else
  {
      returnNO;
  }
}

你可能感兴趣的:(自定义拷贝粘贴窗口)