- 九宫格 分割算法
//要分成的总列数
int totalcolums = 3; // 也可以通过改变列数来修改整体的分布情况
//应用的尺寸信息
CGFloat appw = 80;
CGFloat apph = 100;
//每隔app之间的间隔
CGFloat margin =(self.view.frame.size.width - appw*3)/4;
for (int i = 0; i<data.count; i++)
{
//创建小app框架
UIView *appview = [[UIView alloc]init];
//设置背景颜色
appview.backgroundColor = [UIColor redColor];
//计算每个app框架的位置
//计算行号和列号
int row = i / totalcolums;
int col = i % totalcolums;
CGFloat appx = margin + col * (appw + margin);
CGFloat appy = 30 + row * (apph +margin);
appview.frame = CGRectMake(appx, appy, appw, apph);
//添加到父视图当中
[self.view addSubview:appview];
}
}