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

- (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

uilabel 复制的更多相关文章

  1. ios label 简单的长按复制文本信息

    在iOS开发过程中,有时候会用到UILabel展示的内容,那么就设计到点击UILabel复制它上面展示的内容的功能,也就是Label长按复制功能.网上有很多种给Label添加长按复制功能的方法,这里我 ...

  2. IOS --关于粘贴板 ,剪切板 ,UILabel的复制

    在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framework提供了几个类和协议方便我们在自己的应用程 ...

  3. UIPasteboard粘贴板:UIlabel开启复制粘贴功能(一)

    首先,因为苹果只放出来了 UITextView,UITextField,webView三个控件的剪贴板,所以一般控件的剪贴板都被禁用了,因此,我们首先要做的就是把这属性放出来,其实就是实现三个简单的方 ...

  4. 给文本标签UILabel添加长按复制功能

    http://www.111cn.net/sj/iOS/104236.htm http://blog.csdn.net/lrenjun/article/details/12582927 自定义一个可复 ...

  5. ios 复制黏贴板的使用

    在iOS中,可以使用剪贴板实现应用程序之中以及应用程序之间实现数据的共享.比如你可以从iPhone QQ复制一个url,然后粘贴到safari浏览器中查看这个链接的内容. 一.在iOS中下面三个控件, ...

  6. Swift - UIPasteboard剪贴板的使用详解(复制、粘贴文字和图片)

    转载自:http://www.hangge.com/blog/cache/detail_1085.html UITextField.UITextView组件系统原生就支持文字的复制,但有时我们需要让其 ...

  7. UILabel自适应高度

    在网上看了一些,发现很多关于自适应高度的,不能用,就在下面写一种我常用的吧!保证可以直接粘贴复制到Xcode中运行. UILabel *label = [[UILabel alloc] init]; ...

  8. ios 初体验<UILabel控件>

    创建控件: UILabel *label = [[UILabel alloc]init]; //设置控件大小 label.frame = CGRectMake(50,100,300,40);//分别为 ...

  9. iOS开发之复制字符串到剪贴板

    概述 一般有邀请复制链接需求功能,把字符串复制到系统剪贴板,供用户粘贴使用链接. 详细 代码下载:http://www.demodashi.com/demo/10714.html 一.主要思路 1.在 ...

随机推荐

  1. Dynamic Programming - leetcode [动态规划]

    115. Distinct Subsequences 96. Unique Binary Search Trees 120. Triangle 123. Best Time to Buy and Se ...

  2. python 之文本搜索与替换文件中的文本

    #!/usr/local/env python import os, sys nargs = len(sys.argv) if not 3 <= nargs <= 5: print &qu ...

  3. 洛谷-求同构数的个数-NOIP2013提高组复赛

    题目描述 Description 所谓同构数是指这样的数,即它出现在它的平方数的右端.例如,5的平方是25 (即5×5=25),5是25右端的数,那么5就是同构数.又如,25的平方是625(即25×2 ...

  4. CVE-2014-1767 利用分析(2015.2)

    CVE-2014-1767利用分析 参考这篇文章利用思路,重现利用,主要说明自己在实现的时候遇到的坑. 利用思路 1. 第一次 IoControl,释放 MDL,我们通过 VirtualAddress ...

  5. WEB服务器:Apache、Tomcat、JBoss、WebLogic、Websphere、IIS的区别与关系

    1)Apache  免费,世界使用排名第一的Web服务器.它可以运行在几乎所有广泛使用的计算机平台上.Apache的特点是简单.速度快.性能稳定,并可做代理服务器来使用.Apache是以进程为基础的结 ...

  6. libimobiledevice命令

    Mac 安装 1. 安装HomeBrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/m ...

  7. CSS 选择器之基本选择器 属性选择器 伪类选择器

    CSS 选择器 常见的选择器列表图 CSS选择器笔记 基本选择器 通配符选择器(*) 元素选择器(E) 类选择器(.className)    所有浏览器都支持类选择器,但多类选择器(.classNa ...

  8. maven 阿里镜像

    <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>al ...

  9. python+selenium+Eclipse安装

    1.安装python 参考安装python:http://www.cnblogs.com/beyongblue/p/4215740.html 2.安装python管理工具setuptools 3.安装 ...

  10. SublimeLinter 3中使用jshint

    这货得知已久,在sublime2时期对着教程按部就班的凑合用着...不明所以. 今天无意发现SublimeLinter终于出3了,果断装之,鼓捣1个多小时,磕磕绊绊终于成功工作了.期间看了无数英文文档 ...