我将UILabel子类化为此项目创建可复制标签。 UILabel clipboard
这是它的代码:
- (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会准确记录我要在标签内复制的内容,但是内容不会复制到剪贴板。
有什么想法吗?
如何复制图片?