#define Screen_width [[UIScreen mainScreen] bounds].size.width
- (void)viewDidLoad {
[super viewDidLoad];
//要显示的个数
int How = 11;
// 要显示的列数
int lie = 4;
// 中间的间隔
int jiange = 10;
//每行最多3个,根据个数看需要显示几行
int row;
if (How%lie>0) {
row = How/lie+1;
}else{
row = How/lie;
}
// 根据输入的个数打印一个3列的数据 外控制行 内控制列
int xZhou ;
int yZhou ;
for (int i = 0; i < row; i++) {
yZhou = (Screen_width-(lie+1)*jiange)/lie*i+i*jiange+jiange;
for(int y = 0; y< lie; y++){
xZhou = (Screen_width-(lie+1)*jiange)/lie*y+y*jiange+jiange;
if(i*lie+y+1 == How){
break;
}else{
printf("x轴:%d y轴:%d",xZhou,yZhou);
UIButton *addPhotoButton = [[UIButton alloc]initWithFrame:CGRectMake(xZhou, yZhou, (Screen_width-(lie+1)*jiange)/lie, (Screen_width-(lie+1)*jiange)/lie)];
addPhotoButton.backgroundColor = [UIColor greenColor];
[self.view addSubview:addPhotoButton];
printf("*");
}
}
printf(" ");
}
// Do any additional setup after loading the view, typically from a nib.
}