【问题标题】:app-specific UIPasteboard特定于应用程序的 UIPasteboard
【发布时间】:2015-05-22 08:48:25
【问题描述】:

我正在尝试创建特定于应用的 UIPasteboard,但在弄清楚如何注册它时遇到了一些问题:

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];

如果我只是创建它,应用程序将继续使用 generalPasteboard。我真的希望我不必手动捕捉剪切/复制/粘贴操作和设置项目。

【问题讨论】:

  • 您如何在粘贴板中复制和粘贴项目?
  • 我需要它来处理 UITextFields。当用户选择并复制文本时。

标签: ios objective-c cocoa-touch uikit uipasteboard


【解决方案1】:

请阅读这篇文章 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]

【讨论】:

  • 您也可以在不调用原始选择器的情况下对其进行调配
【解决方案2】:
//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/

【讨论】:

    【解决方案3】:
    //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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多