46、[ iOS ] 复制字符串到剪切板

1、这部分代码写到点击方法中

    // --复制字符串到剪切板
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    NSString *str            = @"www.baidu.com";
    [pasteboard setString:str];
    if (pasteboard) {

        [self copyToMessage:@"邀请链接已复制"];

    }else {
        
        [self copyToMessage:@"邀请链接复制失败"];
    }

2、提示信息弹框方法

// --
- (void)copyToMessage:(NSString *)string {

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:string preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:alertAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}
46、[ iOS ] 复制字符串到剪切板_第1张图片
效果

你可能感兴趣的:(46、[ iOS ] 复制字符串到剪切板)