UIButton

1、内容概要

按钮是全部UI体系中很是重要的组件,在iOS中按钮UIButton的使用也很是灵活,本文将从如下几点介绍UIButton的使用spa

1.UIButton基础
2.UIButton图片使用
3.圆角按钮
4.复选框按钮
5.倒计时按钮(闪烁问题也轻松解决)
6.贪婪按钮(父控件事件也归我,扩大事件响应区域)

 

2、UIButton基础

2.1建立

UIButton提供了一个简单的构造方法,传人一个UIButtonType枚举code

UIButton *b =[UIButton buttonWithType:UIButtonTypeSystem];

 

Tips:

1.设置按钮标题时,必定要经过orm

[b setTitle:@"肯定" forState:UIControlStateNormal];

不可经过接口

b.titleLabel.text = @"肯定";

 

2.2图片使用

UIButton提供了如下两个接口使用图片:事件

[b setImage:[UIImage imageNamed:@"login.png"] forState:UIControlStateNormal];
[b setBackgroundImage:[UIImage imageNamed:@"login.png"] forState:UIControlStateNormal];

(1)其中接口setImage用来设置按钮的图片,默认状况下,它会与按钮文字水平线性排列(通常图片在左,文字在右)图片

(2)接口setBackgroundImage用来设置按钮的背景图片setImage及按钮文字都会显示在背景图片之上ip

 

这里着重讨论一下setBackgroundImage接口,不少时候,按钮看起来是这样的it

相关文章
相关标签/搜索