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

  • 相关阅读:
    MySQL中B+树索引的使用
    MySQL测试环境遇到 mmap(xxx bytes) failed; errno 12解决方法
    MySQL中Cardinality值的介绍
    MySQL Online DDL
    像编程一样写文章—Markdown
    并发模型—共享内存模型(线程与锁)示例篇
    并发模型之——共享内存模型(线程与锁)理论篇
    并发模型之——基本概念
    通讯协议之——字节序
    IntelliJ IDEA14.1中java项目Maven中没有配置JDK时的问题
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/5867951.html
Copyright © 2011-2022 走看看