自定义拷贝粘贴窗口

转自:http://ios-iphone.diandian.com/post/2012-03-30/18195173


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:[NSArray arrayWithObjects:share, email,print, nil]];
   [menu setTargetRect:self.frame inView:self.superview];
   [menu setMenuVisible:YES animated:YES];

(3)、判断显示哪个menu

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
  [super canPerformAction:action withSender:sender];
 
  if ( action == @selector(share:) || action == @selector(email:) || action == @selector(print:))
  {
      return YES;    
  }
  else
  {
      return NO;
  }
}

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