我試圖創建應用程序特定UIPasteboard,但有一些問題搞清楚如何註冊:應用特定UIPasteboard
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];
如果我只是創建它,應用程序繼續使用generalPasteboard。我真的希望我不必抓住剪切/複製/粘貼操作並手動設置項目。
我試圖創建應用程序特定UIPasteboard,但有一些問題搞清楚如何註冊:應用特定UIPasteboard
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];
如果我只是創建它,應用程序繼續使用generalPasteboard。我真的希望我不必抓住剪切/複製/粘貼操作並手動設置項目。
請閱讀這篇文章 http://nshipster.com/uimenucontroller/(這是關於的UILabel,不是的UITextField但有用的只是舉例和相關信息的複製/粘貼/編輯行動是如何工作的,以及如何自定義其行爲)
我認爲您需要子類UITextField
到MyTextField
例如,並覆蓋-(void)copy:
和-(void)paste:
方法從UIResponderStandardEditActions
。
在你實現這些方法,你應該用你的自定義UIPasteboard
複製文本和粘貼,就像這個答覆中提到,
How to do copy/paste function programmatically in iphone?
,但使用的[UIPasteboard generalPasteboard]
使用[UIPasteboard pasteboardWithName:@"myPasteboard" create:YES]
您也可以調用它們而無需調用原始選擇器 – Lefteris
//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/
你如何複製和粘貼粘貼板上的項目? – Lefteris
我需要它與UITextFields一起使用。當用戶選擇並複製文本時。 –