-1

我在滚动视图中创建了 15 个图像按钮,但只有 1 列,我想将行更改为(4 行 * 4 列)

我怎样才能做到这一点??请先给我一些,谢谢。。

NSUInteger booknumber;
for (booknumber = 1; booknumber <= 15; booknumber++) {
   UIButton *button = [self createBtn:booknumber orgx:orgx orgy:orgy];
}

orgx += 100;
orgy += 0;

orgx++;
[mFavorites addSubview:button];


- (UIButton*)createBtn:(int)day orgx:(CGFloat)orgx orgy:(CGFloat)orgy{
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"backplane.png"] forState:UIControlStateNormal];
    button.frame = CGRectMake(orgx, orgy, 75, 113);

    return button;
}
4

1 回答 1

0

试试看:

int booknumber = 1;
for (int i = 0; i < 4; i++) {
  for (int j = 0; j < 4; j++) {
    int orgX = i * 100;
    int orgY = j * 100;
    if (i == 3 && j == 3) return;
    UIButton *button = [self createBtn:booknumber orgx:orgX orgy:orgY];
    [mFavorites addSubview:button];
    booknumber++;
  }
}

希望能帮助到你

于 2012-05-09T08:16:07.187 回答