ios在ios uibutton 边框中的事件有哪些

51CTO视频课程推荐:
2001人学习
11803人学习
18411人学习
查看:1537|回复:2
提示: 作者被禁止或删除 内容自动屏蔽
助理工程师
tapCount是多点触摸,不是多次吧?
助理工程师
tapCount是触摸次数,我之前一直是这么用的,没有问题的第一、UIButton的定义
& &&UIButton&*button=[[UIButton buttonWithType:(UIButtonType);
能够定义的button类型有以下6种,&typedef enum {&UIButtonTypeCustom = 0, 自定义风格
&UIButtonTypeRoundedRect, 圆角矩形&
&UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用
&UIButtonTypeInfoLight, 亮色感叹号&UIButtonTypeInfoDark, 暗色感叹号UIButtonTypeContactAdd, 十字加号按钮
&} UIButtonT
第二、设置frame
button1.frame = CGRectMake(20, 20, 280, 40);
[button&setFrame:CGRectMake(20,20,50,50)];
第三、button背景色
button1.backgroundColor = [UIColor clearColor];
[button&setBackgroundColor:[UIColor&blueColor]];
第四、state状态
&forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现
enum {UIControlStateNormal = 0, 常规状态显现&&UIControlStateHighlighted = 1 && 0, 高亮状态显现&&UIControlStateDisabled = 1 && 1, 禁用的状态才会显现&UIControlStateSelected = 1 && 2, 选中状态&&UIControlStateApplication = 0x00FF0000, 当应用程序标志时&
&UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管他&};
@property(nonatomic,getter=isEnabled)BOOL&& & & & & & & & & & & & & & & & &// default is YES. if NO, ignores touch events and subclasses may draw differently
@property(nonatomic,getter=isSelected)BOOL&& & & & & & & & & & & & & & & &// default is NO may be used by some subclasses or by application
@property(nonatomic,getter=isHighlighted)BOOL& & & & & & & & & & & & & &
第五 、设置button填充图片和背景图片
& &&[buttonsetImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];
& &&[buttonsetBackgroundImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];
第六、设置button标题和标题颜色
[button1 setTitle:@"点击" forState:UIControlStateNormal];
& [buttonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];
第七、设置按钮按下会发光
& &&button.showsTouchWhenHighlighted=NO;
第八、添加或删除事件处理
[button1 addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];
[btn removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
第九、&设置按钮内部图片间距和标题间距
&UIEdgeI // 设置按钮内部图片间距&insets.top = insets.bottom = insets.right = insets.left = 10;&bt.contentEdgeInsets =&bt.titleEdgeInsets = // 标题间距
阅读(...) 评论()ios在uibutton中的事件有哪些_百度知道
ios在uibutton中的事件有哪些
我有更好的答案
按默认排序
或者在被拖动时发送:用户点触屏幕:用户按下第二、三、或第四根手指的时候。  UIControlEventAllEditingEvents  通知所有关于文本编辑的事件:  UIControlEventTouchDown  单点触摸按下事件。  UIControlEventEditingDidOnExit  当文本控件内通过按下回车键(或等价行为)结束编辑时。  UIControlEventEditingChanged  当文本控件中的文本被改变时发送通知。用于滑块。  UIControlEventTouchDragOutside  当一次触摸在控件窗口之外拖动时,发送通知,发送通知。  UIControlEventTouchUpOutside  所有在控件之外触摸抬起事件(点触必须开始与控件内部才会发送通知)。  UIControlEventTouchDragEnter  当一次触摸从控件窗口之外拖动到内部时。  UIControlEventTouchUpInside  所有在控件之内触摸抬起事件。  UIControlEventTouchDragExit  当一次触摸从控件窗口内部拖动到外部时。  UIControlEventTouchChanged  当控件的值发生改变时。  UIControlEventTouchCancel  所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者又有新手指落下的时候,在滑块被放下时发送、分段控件,点触计数大于1。你可以配置滑块控件何时发送通知。  UIControlEventEditingDidBegin  当文本控件中开始编辑时发送通知。  UIControlEventEditingDidEnd  当文本控件中编辑结束时发送通知。  UIControlEventTouchDownRepeat  多点触摸按下事件。  UIControlEventAllEvents  通知所有事件  IOS UIButton事件,或者被上锁或者电话呼叫打断、以及其他取值的控件。  UIControlEventAlltouchEvents  通知所有触摸事件。  UIControlEventTouchDragInside  当一次触摸在控件窗口内拖动时
其他类似问题
ios的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
阅读(2424)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'IOS ----UIButton用法详解',
blogAbstract:'这段代码动态的创建了一个UIButton,并且把相关常用的属性都列举了.希望对大家有用.& //这里创建一个圆角矩形的按钮UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];// 能够定义的button类型有以下6种,// typedef enum {// UIButtonTypeCustom = 0, 自定义风格// UIButtonTypeRoundedRect, 圆角矩形&// UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用// UIButtonTypeInfoLight, 亮色感叹号// UIButtonTypeInfoDark, 暗色感叹号// UIButtonTypeContactAdd, 十字加号按钮',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:3,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:1,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'IT界菜鸟',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}4353人阅读
今天写了这么一小段测试代码,如下:
CGRect imageRect = (CGRect){100, 100, 100, 100};
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:imageRect] autorelease];
imageView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:imageView];
UIButton *maskBtn = [UIButton buttonWithType:UIButtonTypeCustom];
maskBtn.frame = imageView.
maskBtn.backgroundColor = [UIColor redColor];
[maskBtn addTarget:self action:@selector(maskBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:maskBtn];
结果点击按钮不响应事件,小纠结了一下,在得到信息:
UIImageView&has&userInteractionEnabled&set
default. You are adding the button as a subview to the image view. You should set it to&YES.
所以,添加了一行代码,设置imageView响应用户交互即可:
CGRect imageRect = (CGRect){100, 100, 100, 100};
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:imageRect] autorelease];
imageView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:imageView];
imageView.userInteractionEnabled = YES;
UIButton *maskBtn = [UIButton buttonWithType:UIButtonTypeCustom];
maskBtn.frame = imageView.
maskBtn.backgroundColor = [UIColor redColor];
[maskBtn addTarget:self action:@selector(maskBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:maskBtn];
这纯粹就是一个知识点引发的坑,因为以前在UIImageView上都是使用TapGesture来响应用户交互的,所以对这个坑没有太大印象 —— 我遇到过没?
上面代码所构建的视图层级大致如下:
其中红色方框代表的是UIImageView上的UIButton按钮。
参考文档,当用户在红色按钮上点击了一下后:
1. 硬件设施会通知UIKit有触摸事件;
2. UIKit将触摸事件信息封装成对象,分发给合适的视图;
& & 1) UIKit将事件对象放到当前App的事件队列中;
& & 2) 参考文档,当前App会从事件队列取出一个事件对象,然后发送给key window对象;
& & 3) key window对象通过获取触摸事件发生时所在的视图对象;
& & 4) 通过Hit-Testing获得的视图成为第一个可以响应事件的对象,first responder,如果它不响应,则事件对象会沿着响应者链传递。响应者链,即Responder Chain,是由first responder到当前App对象所构成的一串对象,它们都继承于UIResponder类;
P.S. 具体描述可以。
3. 找到合适的处理事件的对象,比如上面代码是self(ViewController),响应事件做些事情;如果找不到就丢弃掉。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:599741次
积分:8564
积分:8564
排名:第718名
原创:186篇
评论:773条
文章:14篇
阅读:16398
文章:14篇
阅读:107629
(1)(1)(1)(5)(3)(3)(1)(1)(2)(2)(4)(1)(1)(1)(3)(1)(3)(1)(1)(12)(5)(4)(4)(5)(10)(4)(3)(1)(1)(18)(5)(1)(4)(3)(1)(2)(1)(1)(1)(1)(1)(6)(6)(2)(4)(8)(4)(2)(10)(11)(7)(3)(3)(1)(6)}

我要回帖

更多关于 ios uibutton 边框 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信