标签:
UIButton继承关系如下:
UIButton-->UIControl-->UIView-->UIResponder-->NSObject
1、创建一个UIButton对象
UIButton提供了如下类方法来创建一个指定类型的UIButton对象
1 + (void)buttonWithType:(UIButtonType)buttonType
UIButtonType是一个枚举类型
1 typedef enum{ 2 UIButtonTypeCustom = 0; //此属性表明,该按钮的外观行为主要依靠开发者的设置 3 UIButtonTypeSystem, //IOS系统默认的按钮风格 4 UIButtonTypeDetailDisclosure, //用于显示当前列表项的详情 5 UIButtonTypeInfoLight, //该按钮用于显示简短的说明(Light) 6 UIButtonTypeInfoDark, //该按钮用户显示简短的说明(Dark) 7 UIButtonTypeContactAdd, //该按钮通常用于添加联系人 8 UIButtonTypeRoundedRect, //圆角矩形的按钮 9 } UIButtonType;
UIButton *button=[[UIButton buttonWithType:(UIButtonType);
2、设置frame
button.frame = CGRectMake(20, 20, 280, 40);
[button setFrame:CGRectMake(20, 20, 280, 40)];
3、button 背景颜色
button.backgroundcolor = [UIColor clearColor];
[button setBackgroundColor:[UIColor clearColor]];
4、state状态
forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现
enum { UIControlStateNormal = 0, //常规状态显现 UIControlStateHighlighted = 1 << 0, //高亮状态显现 UIControlStateDisabled = 1 << 1, //禁用的状态才会显现 UIControlStateSelected = 1 << 2, //选中状态 UIControlStateApplication = 0x00FF0000, //当应用程序标志时 UIControlStateReserved = 0xFF000000 //为内部框架预留,可以不管他 };
5、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;
标签:
原文地址:http://www.cnblogs.com/lifedesi/p/4340500.html