自定义(这里主要是改掉系统拷贝的名字为复制) http://www.jianshu.com/p/557530bcd417
1)添加手势
//在自定义cell中的init方法加入
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressCellHandle:)];
self.longGesture = longPressGesture;
[self addGestureRecognizer:longPressGesture];
2)响应事件
//并加上几个方法
-(void)longPressCellHandle:(UILongPressGestureRecognizer *)gesture {
[self becomeFirstResponder];
UIMenuController *menuController = [UIMenuController sharedMenuController];
UIMenuItem *copyItem = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(menuCopyBtnPressed:)];
menuController.menuItems = @[copyItem];
[menuController setTargetRect:gesture.view.frame inView:gesture.view.superview];
[menuController setMenuVisible:YES animated:YES];
[UIMenuController sharedMenuController].menuItems=nil;
}
// 将要复制的内容复制到系统的剪贴板
- (void)menuCopyBtnPressed:(UIMenuItem *)menuItem {
// 通用的粘贴板
[UIPasteboard generalPasteboard].string = self.messageLab.text;
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(menuCopyBtnPressed:)) {
return YES;
}
return NO;
}