UIButton

UIButton即按钮,可以通过两种方法定义:

1)initWithFrame

	UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(60, 60, 200, 60)];
   	btn.backgroundColor=[UIColor greenColor];
    	[btn setTitle:@"xuan" forState:UIControlStateNormal];
    	[self.view addSubview:btn];
   2)buttonWithType
	
	UIButton *btn2=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    	CGRect rect=CGRectMake(60, 160, 200, 60);
    	btn2.frame=rect;
    	btn2.tag=1001;
    	btn2.backgroundColor=[UIColor colorWithRed:30/255.0 green:200/255.0 blue:125/255.0 alpha:1.0];
    	[btn2 setTitle:@"xuan" forState:UIControlStateNormal];
    	[btn2 addTarget:self action:@selector(btn2Pressed) forControlEvents:UIControlEventTouchDown];
    	[self.view addSubview:btn2];
	-(void)btn2pressed{
	NSLog(@"Button pressed!");
	}
	button的type类型:
	
typedef enum {
    UIButtonTypeCustom = 0,           // no button type   自定义,无风格
    UIButtonTypeRoundedRect,          // rounded rect, flat white button, like in address card 白色圆角矩形,类似偏好设置表格单元或者地址簿卡片
    UIButtonTypeDetailDisclosure,//蓝色的披露按钮,可放在任何文字旁
    UIButtonTypeInfoLight,//微件(widget)使用的小圆圈信息按钮,可以放在任何文字旁
    UIButtonTypeInfoDark,//白色背景下使用的深色圆圈信息按钮
    UIButtonTypeContactAdd,//蓝色加号(+)按钮,可以放在任何文字旁
} UIButtonType;
    UIButton常用的设置方法:
	

//设置对应状态的标题内容default is nil. title is assumed to be single line

- (void)setTitle:(NSString *)title forState:(UIControlState)state;  

//设置对应状态的标题颜色           

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;   

//设置对应状态的标题阴影颜色            

- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state;          

//设置对应状态的按钮的图片

- (void)setImage:(UIImage *)image forState:(UIControlState)state;        

//设置对应状态的按钮背景图片

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state; 

UIButton的常用属性:

titleLabel,buttonType,currentTitle,currentTitleColor,currentTitleShadowColor,currentImage,currentBackgroundImage,imageView, 








                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值