Ios 特定于应用程序的UIPasteboard
我正在尝试创建特定于应用程序的UIPasteboard,但在确定如何注册时遇到一些问题:Ios 特定于应用程序的UIPasteboard,ios,objective-c,cocoa-touch,uikit,uipasteboard,Ios,Objective C,Cocoa Touch,Uikit,Uipasteboard,我正在尝试创建特定于应用程序的UIPasteboard,但在确定如何注册时遇到一些问题: UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES]; 若我只是创建它,那个么应用程序将继续使用generalPasteboard。我真的希望我不必捕捉剪切/复制/粘贴操作并手动设置项目 //Copy your text field text and Just App in Paste
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];
若我只是创建它,那个么应用程序将继续使用generalPasteboard。我真的希望我不必捕捉剪切/复制/粘贴操作并手动设置项目
//Copy your text field text and Just App in Pasteboard
NSString * text=textfield.text;
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setString:text];
下面是关于粘贴板的教程。
请阅读这篇文章
(它是关于UILabel的,而不是UITextField,但仅用于示例和有关复制/粘贴/编辑操作如何工作以及如何自定义其行为的信息)
例如,我认为您需要将UITextField
子类化为MyTextField
,并覆盖-(void)copy:
和-(void)paste:UIResponderStandardEditActions
中的方法
在实现这些方法时,您应该使用自定义的UIPasteboard
将文本复制到其中并从中粘贴,如本答案中所述
但是不要使用[UIPasteboard generalPasteboard]
而是使用[UIPasteboard pasteboardWithName:@“myPasteboard”创建:是]
如何在pasteboard中复制和粘贴项目?我需要它来处理UITextFields。当用户选择并复制文本时。您也可以在不调用原始选择器的情况下滑动文本
//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
}