我正在寻找一个如何将文本复制到iOS剪贴板的简洁示例,然后可以在其他应用程序中使用/粘贴.
此功能的好处是可以快速复制文本,而无需传统文本复制的标准文本突出显示功能.
NSString *copyStringverse = [[NSString alloc] initWithFormat:@"%@",[textview.text]];
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];
Run Code Online (Sandbox Code Playgroud)
我使用上面的代码复制内容 textview
,但我想复制表格的单元格中的内容.这该怎么做.提前致谢.
我尝试使用以下代码将图像数据复制到UIPasteboard
单击菜单中的复制项目.
UIPasteboard *gpBoard = [UIPasteboard generalPasteboard];
[[gpBoard setData:UIImageJPEGRepresentation(imgView.image, 1.0) forPasteboardType:UIPasteboardTypeListImage];
Run Code Online (Sandbox Code Playgroud)
我必须发送哪个参数forPasteboardType
:以及复制数据后如何测试?
我的应用程序应该能够将自定义元数据条目写入PNG图像以导出到UIPasteboard.
通过拼凑关于这个主题的各种帖子,我已经能够提出下面给出的课程作为来源.
使用按钮触发copyPressed方法,我可以使用JPG图像(EXIF)设置自定义元数据:
Image[6101:907] found jpg exif dictionary
Image[6101:907] checking image metadata on clipboard
Image[6101:907] {
ColorModel = RGB;
Depth = 8;
Orientation = 1;
PixelHeight = 224;
PixelWidth = 240;
"{Exif}" = {
ColorSpace = 1;
PixelXDimension = 240;
PixelYDimension = 224;
UserComment = "Here is a comment";
};
"{JFIF}" = {
DensityUnit = 0;
JFIFVersion = (
1,
1
);
XDensity = 1;
YDensity = 1;
};
"{TIFF}" = {
Orientation = 1;
};
}
Run Code Online (Sandbox Code Playgroud)
虽然我能够很好地阅读PNG元数据,但我似乎无法写入:
Image[6116:907] found …
Run Code Online (Sandbox Code Playgroud) 有没有办法做到这一点?我UIPasteboardChangedNotification
在发布时注册了我的对象,但是当它发送到后台并打开(例如)Safari并复制一些文本时,我的处理程序永远不会被调用.(我现在只使用模拟器).
我用过两个:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pasteboardNotificationReceived:)
name:UIPasteboardChangedNotification
object:[UIPasteboard generalPasteboard]];
Run Code Online (Sandbox Code Playgroud)
和:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pasteboardNotificationReceived:)
name:UIPasteboardChangedNotification
object:nil ];
Run Code Online (Sandbox Code Playgroud)
注册我的处理程序.
如何在粘贴板中复制NSAttributedString,以允许用户粘贴或以编程方式粘贴(使用- (void)paste:(id)sender
UIResponderStandardEditActions协议).
我试过了:
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
[pasteBoard setValue:attributedString forPasteboardType:(NSString *)kUTTypeRTF];
Run Code Online (Sandbox Code Playgroud)
但这次崩溃:
-[UIPasteboard setValue:forPasteboardType:]: value is not a valid property list type'
Run Code Online (Sandbox Code Playgroud)
这是预期的,因为NSAttributedString不是属性列表值.
如果用户在我的应用中粘贴了粘贴板的内容,我希望保留属性字符串的所有标准和自定义属性.
我想将.gif图像复制到剪贴板,以便用户可以将gif图像从应用程序粘贴到邮件等...
我试过了 :-
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://fc05.deviantart.net/fs37/f/2008/283/a/b/KaleidoCoils_animated__gif_by_1389AD.gif"]];
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
[pasteBoard setImage:[UIImage imageWithData:data]];
Run Code Online (Sandbox Code Playgroud)
但它的格式为.png而不是.gif.如何将带动画的.gif图像复制到剪贴板,可以在其他应用程序中用作粘贴选项?
应用程序https://itunes.apple.com/us/app/animated-3d-emoji+emoticons/id429348043?mt=8已经这样做了.
请帮我.
提前致谢
尝试将多个数据表示放在iPhone 3.0上的粘贴板上时遇到了一些问题.
我要做的是将数据表示和字符串表示放在粘贴板上.数据是我自己的数据类型,我用它来复制和粘贴我的应用程序.字符串表示是一种将我的应用程序内容作为大纲复制并粘贴到其他应用程序(例如Mail.app)的方法.
// payload
NSString *pasteboardString = [selectedNode stringRepresentation];
NSDictionary *pasteboardDictionary = [selectedNode nodeAndSubnodesProperties];
// set payload
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = pasteboardString;
[pasteboard setValue:pasteboardDictionary forPasteboardType:MNTNodesPasteboardType];
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用,因为string属性和setValue:forPasteboardType:methode替换了粘贴板上的第一个表示.我尝试了addItems:但它对我不起作用.
感谢您的任何帮助!
快速简单的问题
当使用带有一些文本的WebView时 - 用户可以从中选择一段文本并按下我创建的UIButton - 运行以下操作:
-(IBAction)copyToClip
{
NSString *copyClip = [UIPasteboard generalPasteboard].string;
NSLog(@"Clip = %@",copyClip);
// (works fine)
}
Run Code Online (Sandbox Code Playgroud)
我想在没有UIButton的情况下调用相同的函数,因此当用户执行"复制"操作时,它将激活上面的代码.(我假设是听众)
什么是适当的听众?
我想在应用程序启动时将文本复制到剪贴板.
我可以使用以下文本从剪贴板中获取可用文本.但是我需要在另一个viewcontroller中使用这个值.如何将此值传递给我的viewcontroller?
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog([UIPasteboard generalPasteboard].string);
}
Run Code Online (Sandbox Code Playgroud) uipasteboard ×10
ios ×7
copy-paste ×4
iphone ×4
cocoa-touch ×3
objective-c ×3
animated-gif ×1
copy ×1
metadata ×1
png ×1
sdk ×1
swift ×1
uikit ×1