【问题标题】:Problem in photo gallery照片库中的问题
【发布时间】:2011-06-09 12:13:51
【问题描述】:

在 iPhone 上,我想一次显示 60 * 60 大小的图像,每行 3 个。我已经设法获得了 3 张图片的第一行,但我在其他方面遇到了麻烦。这是我目前所拥有的:

CGPoint startPoint = CGPointMake(20, 10);
for (int i = 0; i < mNoOfPoses; i++) 
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[self getImageFromName:[mImgArr objectAtIndex:i]] forState:UIControlStateNormal];
    [btn setTag:i];
    [btn addTarget:self action:@selector(displayImage:) forControlEvents:UIControlEventTouchUpInside];
    btn.frame = CGRectMake(startPoint.x, startPoint.y, 60, 60);
    startPoint.x += 40 + btn.frame.size.width;
    if ( i % 4 == 3 ) 
    {
        startPoint.x = 20;
        startPoint.y += 40 + btn.frame.size.height;
    }
    [mScrollView addSubview:btn];
}        

此代码仅显示 8 张图像,而图像数量为 10。

【问题讨论】:

    标签: objective-c cocoa-touch core-graphics


    【解决方案1】:

    我想你想要...

    i % 4 == 0
    

    每 4 个项目的 mod 将为 0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      相关资源
      最近更新 更多