代码段:
CGFloat x = 20;
CGFloat y = 50;
NSArray *textArray = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",];
for (NSUInteger i = 0;i < 9 ;i ++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:textArray[i] forState:UIControlStateNormal];
button.frame = CGRectMake(x, y, 50, 50);
[self.view addSubview:button];
[button addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
button.tag = i+1 ;
x += 80;
if (i == 2) {
y += 60;
x = 20;
}
if (i == 5) {
y += 60;
x = 20;
}
}