您的位置:首页 > 移动开发 > IOS开发

IOS自定义复制、拷贝功能

2013-07-11 18:31 726 查看
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;

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: