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

  • 相关阅读:
    数据绑定控件的上下文Container dodo
    jquery的调试利器:Firebug使用详解 dodo
    Scrum中的角色 dodo
    jquery easyui datagrid的增加,修改,删除 dodo
    计划扑克(Planning Poker) dodo
    windows2003 IIS 服务启动失败,提示‘另一个程序正在使用此文件,进程无法访问',解决方法 dodo
    控件包含代码块(即 <% ... %>),因此无法修改控件集合 dodo
    AppendFormat System.FormatException: 输入字符串的格式不正确 dodo
    Scrum中的燃烧曲线(Burndown Chart) dodo
    在类中获取、使用当前页面 Page 对象的引用 dodo
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/5867951.html
Copyright © 2011-2022 走看看