Ios 在空位置的行和列中生成按钮
我想生成一个包含视图的网格。我需要从1行,1列到3行,6列 如果需要,我的代码现在正在运行,所有视图都已就位:Ios 在空位置的行和列中生成按钮,ios,objective-c,view,cgrect,Ios,Objective C,View,Cgrect,我想生成一个包含视图的网格。我需要从1行,1列到3行,6列 如果需要,我的代码现在正在运行,所有视图都已就位: * * * * * * * * * * * * * * * 但我想留下一些空的地方,例如我想做如下事情: * * * * * * * * * * * * 或: 我的代码: m 如果gameModel.cards count=12(从我的模型中获取),并且如果每行车数=5,我将获得: * * * * * * *
* * * * *
* * * * *
* * * * *
但我想留下一些空的地方,例如我想做如下事情:
* * * * *
* *
* * * * *
或:
我的代码:
m
如果gameModel.cards count=12(从我的模型中获取),并且如果每行车数=5,我将获得:
* * * * *
* * * * *
* *
我想你可以在一个阵列中创建所有帧,然后从阵列中生成按钮。你能显示你得到的输出而不是想要的输出吗
-(void) generateCardViews {
int positionsLeftInRow = CARDS_PER_ROW;
int j = 0; // j = ROWNUMBER (j = 0) = ROW1, (j = 1) = ROW2...
for (int i = 0; i < [self.gameModel.cards count]; i++) {
NSInteger value = ((CardModel *)self.gameModel.cards[i]).value;
CGFloat x = (i % CARDS_PER_ROW) * 121 + (i % CARDS_PER_ROW) * 40 + 285;
if (j == 1) {
x += 80; // set additional indent (horizontal displacement)
}
if (j == 2) {
x -= 160;
}
CGFloat y = j * 122 + j * 40 + 158;
CGRect frame = CGRectMake(x, y, 125, 125);
CardView *cv = [[CardView alloc] initWithFrame:frame andPosition:i andValue:value];
}
* * * * * *
* * * * * *
* * * * * *
* * * * *
* * * * *
* *