ios小知识点

iOS 复制和粘贴

2017-09-07  本文已影响73人  jay_den

UIPasteboard有系统级别和应用级别两种类型,所以不仅可以在应用程序内通信,还能在应用程序间通信,比如我复制一个url,然后打开safari,粘贴到地址栏去,而我们可以在应用程序间通信、共享数据。

全局使用

//系统级别
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = @"复制的内容";

内部使用--copy

 //应用内单独使用时
    NSString * strBuildID = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleIdentifier"];
    UIPasteboard * myPasteboard = [UIPasteboard pasteboardWithName:strBuildID create:YES];
    myPasteboard.string = @"复制测试数据";     

内部使用--paste

 NSString * strBuildID = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleIdentifier"];
    UIPasteboard * myPasteboard = [UIPasteboard pasteboardWithName:strBuildID create:NO];
    self.pLabel.text = myPasteboard.string;
上一篇下一篇

猜你喜欢

热点阅读