自定义拷贝粘贴窗口

转自: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;
  }
}

转载请注明: 转自Rainbird的个人博客
   本文链接: 自定义拷贝粘贴窗口


相关博文

    分享到:

About rainbird

IOS攻城狮
This entry was posted in IOS开发, object-c, 转载 and tagged , , , , , . Bookmark the permalink.

发表评论