style定义按钮的风格。可用的风格有:
UIBarButtonItemStylePlain 默认按钮风格;按下时会闪动
UIBarButtonItemStyleBordered 与UIBarButtonItemStylePlain相同,但显示的按钮有边框
UIBarButtonItemStyleDone 显示一个蓝色按钮,提醒用户编辑完毕时应该点触(tap)该按钮。
for (int i = 0; i < 9; i ++) {
//起始位置 + 列位置 + 列间距
int n = 20 + i % 3 * 90 + i % 3 * 20;//前后20是 X轴 每一格之间 的间距
// 上下间距 + 行位置 + 行间距
int m = 10 + i / 3 * 90 + i / 3 * 20;
UIButton * bun = [UIButton buttonWithType:UIButtonTypeCustom];
//设置frame
bun.frame = CGRectMake(n, m, 60, 60);
//设置按钮的颜色
[bun setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[你的数组名字 objectAtIndex:i]]] forState:UIControlStateNormal];
//高亮状态
[bun setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
[bun setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//监听方法
[bun addTarget:self action:@selector(buttonSix:) forControlEvents:UIControlEventTouchUpInside];
//添加到view
[self.view addSubview:bun];
}
//监听方法.记得传参
- (void)buttonSix:(UIButton *)but {
//我在属性中设置了一个label 并在窗口中显示了要选择按钮的信息 这里就不写了.框架就是这样子了
self.label.text = [NSString stringWithFormat:@"您选则了 %@ ",bnt.titleLabel.text];
NSLog(@"%@",bnt.titleLabel.text);
}