我正在尝试创建特定于应用程序的UIPasteboard,但在如何注册它时遇到了一些问题:
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];如果我只是创建它,应用程序继续使用generalPasteboard。我真的希望我不必捕获剪切/复制/粘贴操作并手动设置项。
发布于 2015-05-22 09:18:31
请阅读本文http://nshipster.com/uimenucontroller/ (它是关于UILabel,而不是UITextField,但只是有用的,例如,关于复制/粘贴/编辑操作以及如何定制其行为的信息)
例如,我认为您需要将UITextField子类为MyTextField,并从UIResponderStandardEditActions重写-(void)copy:和-(void)paste:方法。
在实现这些方法时,应该使用自定义UIPasteboard将文本复制并粘贴到其中,如本答案所述,
How to do copy/paste function programmatically in iphone?
但是,不要使用[UIPasteboard generalPasteboard],而是使用[UIPasteboard pasteboardWithName:@"myPasteboard" create:YES]
发布于 2015-05-22 09:18:27
//Copy your text field text and Just App in Pasteboard
NSString * text=textfield.text;
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setString:text];下面是一个关于纸板的教程。http://hayageek.com/uipasteboard-example-read-write-share/
发布于 2018-03-13 14:35:55
//pasteboard initialization
let pasteBoard = UIPasteboard.general
// copying the content of textview to pasteboard
if(pasteBoard.hasStrings){
pasteBoard.string = textViewPB.text
}
//pasting the content of pasteboard to textview
if(pasteBoard.hasStrings){
textViewPB.text = pasteBoard.string
}https://stackoverflow.com/questions/30392257
复制相似问题