本文來源地址:http://www.osjoin.com/ios/69.html
- (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(洲洲哥學院)
歡迎各位一塊學習,提高逼格!
也可以添加洲洲哥的微信公衆號