- (void)viewDidLoad {
[super viewDidLoad];
//1.总列数(一行最多3列)
int totalColumns=;
CGFloat appW=;
CGFloat appH=;
//2.间隙=(控制器的view的宽度-3*应用宽度)/4
CGFloat margin=(self.view.frame.size.width-totalColumns*appW)/(totalColumns+);
//3.根据应用个数创建对应的框
for (int index=; index<self.apps.count; index++) {
//NSDictionary *dict=self.apps[index];//字典
//appModel *model=self.apps[index];//模型
//创建一个view
UIView *appView=[[UIView alloc] init];
//设置背景色
appView.backgroundColor=[UIColor redColor];
//计算出行号和列号
int row=index/totalColumns;
int col=index%totalColumns;
//每个格的坐标
CGFloat appX=margin+col * (appW+margin);
CGFloat appY=+row*(appH + margin);
appView.frame=CGRectMake(appX, appY, appW, appH); [self.view addSubview:appView];
}
}
05-02 18:31