Button的功能很黄很暴力,即能显示文字,又能显示图片,还能随时调整内部图片和文字的位置,用的地方很多。

(1)按钮常用的四种状态:

  normal(普通状态)

  默认情况(Default)

  对应的枚举常量:UIControlStateNormal

  highlighted(高亮状态)

  按钮被按下去的时候(手指还未松开)

  对应的枚举常量:UIControlStateHighlighted

  selected (选中状态)

  选没选中由我们自行设定

  对应的枚举常量:UIControlStateSelected

  disabled(失效状态,不可用状态)

  如果enabled属性为NO,就是处于disable状态,代表按钮不可以被点击

  对应的枚举常量:UIControlStateDisabled

(2)创建button:+ (id)buttonWithType:(UIButtonType)buttonType;

typedef NS_ENUM(NSInteger, UIButtonType) {

UIButtonTypeCustom = 0,            // no button type

UIButtonTypeSystem,                // standard system button

UIButtonTypeDetailDisclosure,

UIButtonTypeInfoLight,

UIButtonTypeInfoDark,

UIButtonTypeContactAdd,

  常用的是UIButtonTypeCustom和UIButtonTypeSystem,一般选用UIButtonTypeSystem,当你需要对button进行一些个性化的设置时,比如button的选中状态与未选中状态,字体,图片这些不同时,就必须要选择UIButtonTypeCustom,不然,选中状态时,按钮的上面会出现一个蓝色的竖条条。

UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated, use UIButtonTypeSystem instead

};

(2)按钮的常用属性

  Button.titleLabel.font = [UIFont systemFontOfSize:20];   //改变button字体大小

(3)button的描边

(4)button的四角设置弧度

(5)

(6)

(7)

(8)

(9)

(10)

- (void)viewDidLoad {

[super viewDidLoad];

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

button.frame = CGRectMake(100, 100, 200, 100);

//[button setTitle:@"呵呵..." forState:UIControlStateNormal];

//button.backgroundColor = [UIColor lightGrayColor];

//[button setTintColor:[UIColor yellowColor]];

button.titleLabel.text = @"hehe";

button.showsTouchWhenHighlighted=YES;

[button addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];

//将标签加入视图

[self.view addSubview:button];

}

-(void)addButton:(UIButton*)button{

button.selected = !button.selected;

if (button.selected) {

NSLog(@"selected");

button.backgroundColor = [UIColor lightGrayColor];

[button setTitle:@"点我干嘛!" forState:UIControlStateNormal];

NSLog(@"%@",button.currentTitle);

} else {

NSLog(@"unSelected");

[button setTitle:@"呵呵..." forState:UIControlStateNormal];

NSLog(@"%@",button.currentTitle);

}

}

---恢复内容结束---

UIButton常用属性小结(编辑中。。。)的更多相关文章

  1. UILabel常用属性小结

    标签常用的属性: (1)frame属性:设置标签的位置与大小. frame = CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat heig ...

  2. 【iOS】UIButton 常用属性

    发现 UIButton 的相关属性不熟悉了……常用的一些属性代码如下: UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom]; ad ...

  3. IOS UIButton常用属性

    //1.添加按钮 UIButton *nameView=[UIButton buttonWithType:UIButtonTypeCustom]; //nameView.backgroundColor ...

  4. Swift2.0 中的String(一):常用属性

    字符串算是平常用的比较多.花样也比较多的一个类型,昨天有空把相关的一些常用操作都写了一遍,总结出来.其实iOS里面的字符串更复杂,还有NSString系列等等,那些API太多将来需要用的时候再慢慢学. ...

  5. 给iOS开发新手送点福利,简述UIButton的属性和用法

    UIButton属性 1.UIButton状态: UIControlStateNormal          // 正常状态    UIControlStateHighlighted     // 高 ...

  6. UIButton的常用属性

    可以通过代码的方式创建UIButton 通用实例化对象方法: UIButton *button = [[UIButton alloc] initWithFrame:rect]; 快速实例化对象方法: ...

  7. DataGrid中的常用属性

    DataGrid中的常用属性 $('#dg').datagrid({ url:'datagrid_data.json', columns:[[ {field:'code',title:'Code',w ...

  8. Android开发中XML布局的常用属性说明

    <!-- 常用属性说明: android:id="@+id/button" 为控件指定Id android:text="NNNNNNNNNN" 指定控件的 ...

  9. Delphi中TStringList类常用属性方法详解

    TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 先把要讨论的几个属性列出来: 1.CommaText 2.Delim ...

随机推荐

  1. JS里的CSS函数

    <title>无标题文档</title> <script> function css(obj,name,value){ if(arguments.length==2 ...

  2. Linux学习 -- 文件系统管理

    1 分区和文件系统 分区类型 主分区:<= 4个 扩展分区:只能有一个,也算主分区的一种   不能存储数据和格式化,只能用来包含逻辑分区 逻辑分区:扩展分区中划分的   IDE--最多59个   ...

  3. python 从windows上传文件到linux脚本

    import paramiko import datetime import os hostname = '192.168.112.132' username = 'root' password = ...

  4. asp 随机生成字符

    <%function rndNumLetters(num) randomize dim num0,num1,num2,num3,pass if num = "" or not ...

  5. Dojo和jQuery区别

    Dojo类似jQuery,且用法也差不多,但是Dojo属于重量级的框架,自带的表单验证,Grid,tree等控件. 在选择上,个人觉得轻量级的框架比较好,因为方便引入第三方的,有特色的库. 就像选择S ...

  6. IMCP网际控制协议

    IP协议是TCP/IP协议使用的在网络层传输机制,它是一种不可靠的无连接的数据报协议,但是IP协议假定了底层是不可靠的,因此,要尽最大的努力传输到目的地,但正因为如此,IP协议则没有了保证,也就是说, ...

  7. android init.rc 语法分析

    此文来自于对http://source.android.com/porting/index.html中bring up段的简译.其中有一处与源码的 system/core/init/readme.tx ...

  8. eclipse's code assist

    突然发现有个类没有code assist功能了,而别的类都还有,新建的类也有,可是当把代码拷贝到新建的类还是不行:尝试了各种办法,包括删除workspace/.metadata/.plugin/org ...

  9. Modbus RTU 通信工具设计(转)

    Modbus RTU 通信工具设计 Modbus 是一个工业上常用的通讯协议.一种通讯约定. ModBus 协议是应用层报文传输协议(OSI 模型第7层),它定义了一个与通信层无关的协议数据单元(PD ...

  10. 关于go的不爽

    这里想记录下,自己学习.使用go语言,对于go语言不爽的地方. 1. 函数返回类型接在参数类型后面,不容易一眼看清楚函数的返回类型 如下,是不是有种很花的感觉. func NewReader(s st ...