UIButton使用方法汇总
原文链接地址:http://blog.sina.com.cn/s/blog_bf9843bf0101f8hr.html
//按钮初始化类方法
UIButton
//按钮初始化实例方法
UIButton *button1=[[UIButton alloc]initWithFrame:CGRectMake(50, 300, 200, 50)];
//
//
//
//
//
//
//
//
//给定button在view上的位置
[button1 setFrame:CGRectMake(50, 300, 200, 50)];
button1.frame=CGRectMake(50, 300, 200, 50);
//button背景色
[button1 setBackgroundColor:[UIColor redColor]];
button1.backgroundColor=[UIColor redColor];
//设置button填充图片
//[button1
//设置button标题
[button1
//以下是几种状态
//
//
//
//
//
//
//
//
注意:
button1.adjustsImageWhenHighligh
//跟上面的情况一样,默认情况下,当按钮禁用的时候,图像会被画得深一点,设置NO可以取消设置
button1.adjustsImageWhenDisabled
//下面的这个属性设置为yes的状态下,按钮按下会发光
button1.showsTouchWhenHighlighte
按下按钮,并且手指离开屏幕的时候触发这个事件,跟web中的click事件一样。
触发了这个事件以后,执行butClick:这个方法,addTarget:self
也可以传入其他类的指针
[button1
//显示控件
[self.view
注意:
[button1
addTarget:self
action:@selector(alarmTimeDone:)
forControlEvents:UIControlEventTouchUpIns
//取消按钮已经添加的所有事件:(这个比较重要,若添加了两个事件
[btn
何时释放release
是否在dealloc中对UIButton对象进行release操作,取决于UIButton初始化的方式。
如果使用 [UIButtonbuttonWithType:UIButtonTypeRoundedRect]这种方式,是不需要进行release操作的,因为这种方式是自动释放的。如果使用