自定义拷贝,粘贴窗口

(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;
  }
}

 

posted @ 2013-03-05 20:09  追风.扬  阅读(183)  评论(0编辑  收藏  举报