美文网首页
UIActivityViewController 粘贴到剪贴板,

UIActivityViewController 粘贴到剪贴板,

作者: IreneWang1988 | 来源:发表于2016-04-20 15:51 被阅读0次

    1:在UIActivityViewController 里面实现系统自带复制到粘贴板。

    NSArray *activities = (@[act1,act2,act3,act4,act5]);

    NSString *textToShare =  entity.sharedUrl.url;

    NSArray *activityItems = @[textToShare];

    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems

    applicationActivities:activities];

    activityController.excludedActivityTypes = (@[

    UIActivityTypeAssignToContact,

    UIActivityTypeMail,

    UIActivityTypeMessage,

    UIActivityTypePrint,

    UIActivityTypeSaveToCameraRoll,

    UIActivityTypePostToFacebook,

    UIActivityTypeAirDrop

    ]);

    //给activityVC的属性completionHandler写一个block。

    //用以UIActivityViewController执行结束后,被调用,做一些后续处理。

    UIActivityViewControllerCompletionHandler myBlock = ^(NSString *activityType,BOOL completed)

    {

    NSLog(@"activityType :%@", activityType);

    if ([activityType isEqualToString:UIActivityTypeCopyToPasteboard]) {

    if (completed)

    {

    [SVProgressHUD showSuccessWithStatus:@"已粘贴到剪贴板"];

    }

    else

    {

    NSLog(@"cancel");

    }

    }

    };

    // 初始化completionHandler,当post结束之后(无论是done还是cancell)该blog都会被调用

    activityController.completionHandler = myBlock;

    [self presentViewController:activityController animated:YES completion:NULL];

    2: UIButton 实现点击后复制到粘贴板

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

    pasteboard.string = self.shareEntity.sharedUrl.url;

    [SVProgressHUD showSuccessWithStatus:@"已粘贴到剪贴板" duration:2.0f];

    相关文章

      网友评论

          本文标题:UIActivityViewController 粘贴到剪贴板,

          本文链接:https://www.haomeiwen.com/subject/dsnzlttx.html