.
UILabel :
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action
withSender:(id)sender
{
return (action == @selector(copy:));
}
- (void)copy:(id)sender {
[[UIPasteboard generalPasteboard] setString:self.text];
}
, .
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressDetected:)];
[_messageLabel addGestureRecognizer:longPress];
, UIMenuController :
- (void)LongPressDetected:(UILongPressGestureRecognizer*)gesture {
[_messageLabel becomeFirstResponder];
[[UIMenuController sharedMenuController] setTargetRect:_messageLabel.bounds inView:_messageLabel];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:NO];
}