我将 UILabel 子类化以使用该项目创建可复制的标签。 UILabel 剪贴板
这是它的代码:
- (void) copy: (id) sender
{
NSLog(@"Copy handler, label: “%@”.", self.text);
}
- (BOOL) canPerformAction: (SEL) action withSender: (id) sender
{
return (action == @selector(copy:));
}
- (void) handleTap: (UIGestureRecognizer*) recognizer
{
[self becomeFirstResponder];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setTargetRect:self.frame inView:self.superview];
[menu setMenuVisible:YES animated:YES];
}
- (BOOL) canBecomeFirstResponder
{
return YES;
}
并且 NSLog 准确记录了我要在标签内复制的内容,但是,内容不会复制到剪贴板。
任何想法?
以及如何复制图像?