标签:
1
|
UIButton *button = [[UIButton alloc] initWithFrame:rect];
|
1
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
UIButtonTypeCustom
|
按钮的内容需要自定义
|
UIButtonTypeRoundedRect
|
圆角矩形按钮
|
UIButtonTypeDetailDisclosure
|
显示明细按钮
|
UIButtonTypeInfoLight
|
亮色信息按钮,用于深色背景
|
UIButtonTypeInfoDark
|
深色信息按钮,用户浅色背景
|
UIButtonTypeContactAdd
|
添加按钮
|
1
2
3
4
|
//正常状态下按钮文字
[btn setTitle:@"正常" forState:UIControlStateNormal];
//长按按钮状态下的按钮文字
[btn setTitle:@"长按" forState:UIControlStateHighlighted];
|
1
2
|
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
|
1
|
[btn setBackgroundColor:[UIColor orangeColor]];
|
1
2
3
4
5
6
|
// 加载图像
UIImage *image = [UIImage imageNamed:@"sub_black_add.png"];
// 设置按钮图像
[btn setImage:image forState:UIControlStateNormal];
// 设置按钮背景图像
[btn setBackgroundImage:image forState:UIControlStateNormal];
|
1
2
|
// 设置按钮点击监听
[btn addTarget:self action:@selector(tapButton) forControlEvents:UIControlEventTouchUpInside];
|
标签: