【问题标题】:create 15 image into an scrollerview 4 rows * 4 columns将 15 个图像创建为一个 4 行 * 4 列的滚动视图
【发布时间】:2012-05-09 03:46:54
【问题描述】:

我在滚动视图中创建了 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;
}

【问题讨论】:

  • 我尝试用for{},但是什么都不加载(我不知道),还要多学习,请多多指教..
  • 放上你的代码。像这样的问题让人觉得你没有研究,而是来这里让我们做你的工作。至少通过代码,它表明你已经尝试过了。 (顺便说一句,即使显示代码,您也是少数。通常,我们只是在提问者方面毫不费力地得到这些问题)。
  • 原点计算不正确,每次你只是增加x,而你想要一个网格结构?
  • 您可以查看此内容以供参考 - stackoverflow.com/questions/5140710/…

标签: ios uiscrollview uibutton


【解决方案1】:

试试看:

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++;
  }
}

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 2013-02-26
    相关资源
    最近更新 更多