zoukankan      html  css  js  c++  java
  • UILabel 复制

    //添加一个长按响应方法

    - (void)addLongPressGestureRecognizer

    {

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

        [self.contentLabel addGestureRecognizer:longPress];

        self.contentLabel.userInteractionEnabled = YES;

    }

    //长按方法的实现

    - (void)longPress:(UILongPressGestureRecognizer *)sender

    {

        if (sender.state == UIGestureRecognizerStateBegan)

        {

            [self becomeFirstResponder];

            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuItemsHiden) name:UIMenuControllerWillHideMenuNotification object:nil];

            UIMenuItem *copy = [[UIMenuItem alloc]initWithTitle:@"复制" action:@selector(menuCopy:)];

            UIMenuItem * report = [[UIMenuItem alloc]initWithTitle:@"举报" action:@selector(menuReport:)];

            UIMenuController *menu = [UIMenuController sharedMenuController];

            [menu setMenuItems:@[copy,report]];

            [menu setTargetRect:CGRectMake([sender locationInView:self.view].x, [sender locationInView:self.view].y, 0, 0) inView:self.view];

            [menu setMenuVisible:YES animated:YES];

            self.contentLabel.backgroundColor = [UIColor grayColor];

            

        }

    }

    /*!

     *  允许成为第一响应

     */

    - (BOOL)canBecomeFirstResponder{

        return YES;

    }

    /*!

     *  用于控制哪些命令显示在编辑菜单中

     */

    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{

        if (action == @selector(menuCopy:)) {

            return YES;

        }

        if (action == @selector(menuReport:)) {

            return YES;

        }

        return NO;

    }

    /**

     *  @brief 复制的响应方法

     *

     *  @param sender

     */

    -(void)menuCopy:(id)sender

    {

        [UIPasteboard generalPasteboard].string = self.contentLabel.text?self.contentLabel.text:@"";

    }

    /**

     *  @brief 举报的响应方法

     *

     *  @param sender

     */

    -(void)menuReport:(id)sender

    {

        //跳转到举报用户添加 举报类型字段

        NSLog(@"举报的响应方法");

    }

    - (void)menuItemsHiden

    {

        self.contentLabel.backgroundColor = [UIColor whiteColor];

        [[NSNotificationCenter defaultCenter] removeObserver:self];

    }

    //来源:http://blog.cocoachina.com/article/39466

  • 相关阅读:
    谷歌分析配置行为事件
    CentOS7.6下模拟iSCSI,Windows来连
    2.CentOS6.5下的DNS主从区域传送配置
    1.CentOS6.5下的基础DNS配置
    CentOS下搭建DHCP服务
    思科设备配置DHCP服务
    思科网络设备配置AAA认证
    vsftpd文件虚拟用户搭建
    Windows网络服务渗透攻击分类
    使用脚本来监控新建进程及其父进程以及他们的命令行
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/5867951.html
Copyright © 2011-2022 走看看