美文网首页
UIPasteboard 简单使用

UIPasteboard 简单使用

作者: 5a9c6f44e578 | 来源:发表于2017-03-07 14:19 被阅读121次

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;

相关文章

网友评论

      本文标题:UIPasteboard 简单使用

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