UIPasteboard是iOS原生的复制粘贴控件
效果图
冯绍峰粉色粉色.gif全局控件
@property (nonatomic, strong)UITextField *tf;
@property (nonatomic, strong)UILabel *label;
ViewDidLoad 中的布局
self.tf = [[UITextField alloc]initWithFrame:CGRectMake(30, 100, self.view.frame.size.width - 60, 50)];
_tf.placeholder = @"请输入";
[self.view addSubview:self.tf];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor redColor];
button.frame = CGRectMake(50, self.view.frame.size.height - 100, self.view.frame.size.width - 100, 50);
[button setTitle:@"复制" forState:UIControlStateNormal];
[button addTarget:self action:@selector(ButtonAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
self.label = [[UILabel alloc]initWithFrame:CGRectMake(30, 200, self.view.frame.size.width - 60, 50)];
// self.label.layer.backgroundColor = [UIColor grayColor].CGColor;
self.label.layer.borderWidth = 1;
[self.view addSubview:_label];
button 点击事件 UIPasteboard简单使用
// iOS 原生的 剪切板
UIPasteboard *pab = [UIPasteboard generalPasteboard];
[pab setString:self.tf.text];
self.label.text = pab.string;
网友评论