UIButton *aBtn=[UIButtonbuttonWithType:UIButtonTypeCustom];

[aBtn setFrame:CGRectMake(40, 100, 60, 60)];

[aBtn setBackgroundImage:[UIImageimageNamed:@"111.png"] forState:UIControlStateNormal];

//button点击事件

[aBtn addTarget:selfaction:@selector(btnShort:) forControlEvents:UIControlEventTouchUpInside];

//button长按事件

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc] initWithTarget:selfaction:@selector(btnLong:)];

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

[aBtn addGestureRecognizer:longPress];

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

if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {

NSLog(@"长按事件");

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"消息" message:@"确定删除该模式吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"删除", nil];

[alert show];

}

为 UIButton 添加长按事件的更多相关文章

  1. 为自定义的View添加长按事件

    以前开发画板组件时,要添加一个长按监听事件,这个画板实际上就是继承自View的一个自定义组件. 首先,设置好长按事件发生时要触发的操作: private class LongPressRunnable ...

  2. datatables添加长按事件

    长按事件 $.fn.longPress = function (fn) { var timeout = undefined; var $this = this; for (var i = 0; i & ...

  3. iOS 为移动中的UIView(UIButton )添加点击事件

    高高兴兴迎接新的产品新需求,满心欢喜的开始工作,结果研究了一下午才发现,是自己想的太简单了,是我太单纯呀. 需求是这样的类似下雪的效果,随机产生一些小雪花,然后每个雪花可以点击到下个页面. 接到需求之 ...

  4. 使用关联对象(AssociatedObject)为UIButton添加Block响应

    在开发中,要给UIButton添加点击事件的话,通常的做法是这样的 UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [ ...

  5. 触发UIButton长按事件

    UIButton *aBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [aBtn setFrame:CGRectMake(40, 100, 60,  ...

  6. 【Swift 2.1】为 UIView 添加点击事件和点击效果

    前言 UIView 不像 UIButton 加了点击事件就会有点击效果,体验要差不少,这里分别通过自定义和扩展来实现类似 UIButton 的效果. 声明 欢迎转载,但请保留文章原始出处:) 博客园: ...

  7. 「iOS造轮子」之UIButton 用Block响应事件

    俗语说 一个不懒的程序员不是好程序员 造轮子,也只是为了以后更好的coding. coding,简易明了的代码更是所有程序员都希望看到的 无论是看自己的代码,还是接手别人的代码 都希望一看都知道这代码 ...

  8. Android RecyclerView单击、长按事件:基于OnItemTouchListener +GestureDetector标准实现(二),封装抽取成通用工具类

     Android RecyclerView单击.长按事件:基于OnItemTouchListener +GestureDetector标准实现(二),封装抽取成通用工具类 我写的附录文章2,介绍了 ...

  9. Android RecyclerView单击、长按事件标准实现:基于OnItemTouchListener + GestureDetector

     Android RecyclerView单击.长按事件:基于OnItemTouchListener + GestureDetector标准实现 Android RecyclerView虽然拥有L ...

随机推荐

  1. QDialog, QFileDialog 和 QDesktopServices 的使用方法

    Qt中的QDialog类是用来生成对话框的类,QFileDialog 类是QDialog的衍生类,主要用来生成打开文件,或是打开文件目录的对话框,或者是保存文件的对话框,下面我们一一来看代码: 1. ...

  2. Using pg_dump restore dump file on Odoo

    pg_restore -C -d postgres db.dump

  3. easyui datagrid 增删改查示例

    查询JSP页面 <!doctype html> <%@include file="/internet/common.jsp"%> <!-- 新样式右侧 ...

  4. mysql 商品表的设计思路(面向对象建表:类与对象)

    学习地址 http://www.jtthink.com/course/play/352 商品通用信息主表:prop_main 不仔细多说,正常业务都会涉及到并且考虑的相对周全.常用字段[商品id][商 ...

  5. PHP == 和 ===

    == 只判断两边的值是否相等,例如: 5555 == "5555" ,为真 === 判断两边的值和类型是否相当,5555 === "5555"  False,因 ...

  6. 2016.10.08,英语,《Verbal Advantage》Level1 Unit1-4

    这本书学的很辛苦,总共10个Level,每个Level有5个Unit,每个Unit10个单词,实际上自己差不多一天才能学完1个Unit10个单词.(当然,一天我只能花大约1个小时左右在英语上) 而且跟 ...

  7. 2016.07.04,英语,《Vocabulary Builder》Unit 23

    text comes from a Latin verb that means 'to weave'. textile: ['tekstaɪl] adj. 纺织的 n. 纺织品; texture: [ ...

  8. 背景图片与 CSS的那些事

    在CSS中,背景图片的定位方法有3种: 1)关键字:background-position: top left; 2)像素:background-position: 0px 0px; 3)百分比:ba ...

  9. PHP mkdir 方法 创建 0777 权限的目录问题

    php 中使用 mkdir() 方法创建 0777 权限的目录: $path = './Logs/secondCheck/';if(!is_dir($path)){ mkdir($path, 0777 ...

  10. nginx location 匹配顺序

    location 匹配的原型是这样的:location [=|~|~*|^~|@] /uri/ { … } “=”是精确匹配“@”是命名的location ,在正常的location 匹配中不会使用, ...