- typedef enum {
- UIButtonTypeCustom = 0, // no button type 自定义,无风格
- UIButtonTypeRoundedRect, // rounded rect, flat white button, like in address card 白色圆角矩形,类似偏好设置表格单元或者地址簿卡片
- UIButtonTypeDetailDisclosure,//蓝色的披露按钮,可放在任何文字旁
- UIButtonTypeInfoLight,//微件(widget)使用的小圆圈信息按钮,可以放在任何文字旁
- UIButtonTypeInfoDark,//白色背景下使用的深色圆圈信息按钮
- UIButtonTypeContactAdd,//蓝色加号(+)按钮,可以放在任何文字旁
- } UIButtonType;
UIButton* btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(100, 100, 100, 50);
[btn setTitle:@"Normal" forState:UIControlStateNormal];
[btn setTitle:@"Selected" forState:UIControlStateSelected];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
[btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:[UIImage imageNamed:@"0.jpg"] forState:UIControlStateNormal];
[self.view addSubview:btn];
adjustsImageWhenHighlighted
默认情况下,在按钮被禁用时,图像会被画的颜色深一些。要禁用此功能,请将这个属性设置为NO:
- btn1.adjustsImageWhenHighlighted = NO;
adjustsImageWhenDisabled
默认情况下,按钮在被禁用时,图像会被画的颜色淡一些。要禁用此功能,请将这个属性设置为NO:
- btn1.adjustsImageWhenDisabled = NO;
showsTouchWhenHighlighted
这个
属性设置为YES,可令按钮在按下时发光。这可以用于信息按钮或者有些重要的按钮:
- btn1.showsTouchWhenHighlighted = YES;