ios开发之----复制和粘贴

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

全局使用

    //系统级别
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.pTextField.text;
    NSLog(@"\r\n====>输入框内容为:%@\r\n====>剪切板内容为:%@",self.pTextField.text,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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值