CGFloat margin = 10.0f;
CGFloat appViewWidth = (375 - 4 * margin)/3;
CGFloat appViewHeight = (375 - 4 * margin)/3;
//2. 完成布局设计
//三列
int totalloc = 3;
for (int i = 0; i < 9; i++) {
int row = i / totalloc;//行号
int loc = i % totalloc;//列号
CGFloat appViewX = margin + (margin + appViewWidth) * loc;
CGFloat appViewY = margin + (margin + appViewHeight) * row;
//创建UIView控件
UIView *appView = [[UIView alloc] initWithFrame:CGRectMake(appViewX, appViewY, appViewWidth, appViewHeight)];
appView.backgroundColor = [UIColor redColor];
[self.bgView addSubview:appView];
}