九宫格代码
Posted jackie-subdai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了九宫格代码相关的知识,希望对你有一定的参考价值。
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];
}
以上是关于九宫格代码的主要内容,如果未能解决你的问题,请参考以下文章