zoukankan      html  css  js  c++  java
  • 方便快捷的添加button的长按事件,并且复制到剪切板

    先设置一个按钮button【这里不再累述】

    //button长按事件

     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(btnLong:)];

        longPress.minimumPressDuration = 0.8; //定义按的时间

        [_button addGestureRecognizer:longPress];

    -(void)btnLong:(UILongPressGestureRecognizer *)gestureRecognizer{

        if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {

            NSLog(@"长按事件");

            NSString *message = NSLocalizedString(@"是否复制到剪切板?", nil);

            NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);

            NSString *cancleButtonTitle = NSLocalizedString(@"取消", nil);

            

            UIAlertController *homealertController = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];

            

            UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

    //复制文字到剪切板

        UIPasteboard *pboard = [UIPasteboard generalPasteboard];

                pboard.string = _button.titleLabel.text;

                

    //复制图片到剪切板           

                UIPasteboard *pboard = [UIPasteboard generalPasteboard];

                pboard.image =_button.imageView.image;

            }];

            UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancleButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

                

            }];

            

            [homealertController addAction:cancleAction];

            [homealertController addAction:otherAction];

            [self presentViewController:homealertController animated:YES completion:nil];

        }

    }

     以上就可以实现简单快捷的添加按钮的长按事件,并且能够复制到剪切板上,快准狠。。。。。。

  • 相关阅读:
    折线图
    饼图
    VC中custom symbol的方法(For MO)制作带箭头的线
    Yahoo!:美国 RSS 使用状况的调查报告
    中国搜 为人民服务 整合本地搜索引擎 出差旅游搜索国外国内当地服务网站 快速进行本地资源查找利用
    MO自定义符号之二(将点显示为水池符号)
    美国在线公司斥资2.5亿美元收购大批博客网站
    ESRI新的开发网站
    Java: 把金额转换为汉字的类
    常见的网上邻居访问问题汇集
  • 原文地址:https://www.cnblogs.com/wenqian/p/6089342.html
Copyright © 2011-2022 走看看