首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序专用UIPasteboard

应用程序专用UIPasteboard
EN

Stack Overflow用户
提问于 2015-05-22 08:48:25
回答 3查看 1.8K关注 0票数 2

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

代码语言:javascript
复制
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 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]

票数 2
EN

Stack Overflow用户

发布于 2015-05-22 09:18:27

代码语言:javascript
复制
//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/

票数 1
EN

Stack Overflow用户

发布于 2018-03-13 14:35:55

代码语言:javascript
复制
//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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30392257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档