在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张。
答案 0 :(得分:0)
我想你想......
i % 4 == 0
每4个项目的mod为0。