UIButton的知识点整理

UIButton:

UIButton是ios中最常用的视图控件,常用来响应用户的点击事件

UIButton的类是一个UIControl子类,它实现了在触摸屏上的按钮。触摸一个按钮拦截事件和动作消息发送到目标对象.

1.创建一个按钮

UIButton*loginButton=[UIButton buttonWithType:UIButtonTypeSystem];

能够定义的button类型有以下6种,

typedef enum {

UIButtonTypeCustom = 0, 自定义风格

UIButtonTypeRoundedRect, 圆角矩形

UIButtonTypeDetailDisclosure,蓝色小箭头按钮,主要做详细说明用

UIButtonTypeInfoLight, 亮色感叹号

UIButtonTypeInfoDark, 暗色感叹号

UIButtonTypeContactAdd, 十字加号按钮

  } UIButtonType;

 

2.设置位置和大小           

loginButton.frame=CGRectMake(40, 260, 50, 20);


[button setFrame:CGRectMake(20,20,50,50)];

3.设置背景颜色           loginButton.backgroundColor=[UIColor  grayColor];


[button setBackgroundColor:[UIColor blueColor]];            

4.给Button设置标题

 [loginButton setTitle:@"登录"           forState:UIControlStateNormal];

5.给标题改颜色

[loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

6.设置字体大小

            loginButton.titleLabel.font=[UIFont fontWithName:@"Arial" size:15];

7.给Button设置高亮

[loginButton setShowsTouchWhenHighlighted:YES];

            

8.给UIButton来一个背景图片

 UIImage*image=[UIImage imageNamed:@"nlf.png"];

[loginButton setBackgroundImage:image forState:UIControlStateNormal];

            

9.给Button变成圆角

loginButton.layer.cornerRadius=5;

loginButton.layer.masksToBounds=YES;


 10.添加或删除事件处理

[button1 addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];


[btn removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];

            


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值