- (void)rankWithTotalColumns:(int)totalColumns andWithAppW:(int)appW andWithAppH:(int)appH{
//总列数
int _totalColumns = totalColumns;
//view尺寸
CGFloat _appW = appW;
CGFloat _appH = appH;
//横向间隙 (控制器view的宽度 - 列数*应用宽度)/(列数 + 1)
CGFloat margin = (self.view.frame.size.width - (_totalColumns * 85)) / (_totalColumns + 1);
// for (int index = 0; index < self.appsArray.count; index++) {
for (int index = 0; index < 5; index++) {
//创建一个小框框//
UIView *appView = [[UIView alloc] init];
appView.backgroundColor = [UIColor redColor];
//创建结束//
//计算框框的位置...行号列号从0开始
//行号
int row = index / totalColumns; //行号为框框的序号对列数取商
//列号
int col = index % totalColumns; //列号为框框的序号对列数取余
// 每个框框靠左边的宽度为 (平均间隔+框框自己的宽度)
CGFloat appX = margin + col * (appW + margin);
// 每个框框靠上面的高度为 平均间隔+框框自己的高度
CGFloat appY = 30 + row * (appH + margin);
appView.frame = CGRectMake(appX, appY, _appW, _appH);
[self.view addSubview:appView];
}
}
如有问题可添加我的QQ:1290925041
还可添加QQ群:234812704(洲洲哥学院)
欢迎各位一块学习,提高逼格!
也可以添加洲洲哥的微信公众号
网友评论