46、[ iOS ] 复制字符串到剪切板
2016-07-07 本文已影响236人
天听云道
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];
}
效果