Btton 的 常用方法
只是简单的 总结 一下 经常用的 Buttonde 使用方法
初学者 看看还是挺好接受的
初始化
在使用MRC 的时候 最好 使用 构造器 因为此构造器无需考虑引用计数
UIButton *button = [UIButton buttonWithType:5];
因为buttonWithType 为 枚举类型 即可以写它的代号
也可以写它的名字 以下为它的成员
UIButtonTypeCustom = 0, // no button type
UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), // standard system button
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
UIButtonTypeRoundedRect = UIButtonTypeSystem, // Deprecated, use UIButtonTypeSystem instead
设置
button.frame = CGRectMake(30, 30, 30, 30);
设置背景颜色
button.backgroundColor = [UIColor whiteColor];
设置button上的文字
state :枚举类型 表示button现在的状态
UIControlStateNormal = 0,
UIControlStateHighlighted = 1 << 0, // used when UIControl isHighlighted is set
UIControlStateDisabled = 1 << 1,
UIControlStateSelected = 1 << 2, // flag usable by app (see below)
UIControlStateApplication = 0x00FF0000, // additional flags available for application use
UIControlStateReserved = 0xFF000000 // flags reserved for internal framework use
[button setTitle:@"按钮" forState:UIControlStateNormal];
设置button文字颜色
button文字默认颜色为蓝色
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
添加点击事件 就是给按钮绑定一个 方法
[button addTarget:(id) action:(SEL) forControlEvents:(UIControlEvents)];
参数1(id位置):执行方法的对象self
参数2(SEL位置):方法名称
参数3 (UIControlEvents) :button处于什么状态时候触发方法