[英]To make an photo gallery in iphone
On the iPhone I would like to display 13 image at a time, with 4 of them on each row.在 iPhone 上,我想一次显示 13 张图像,每行 4 张。 I've managed to get the first row with 4 images, but I'm having trouble with the rest.
我已经设法获得了 4 张图像的第一行,但我在使用 rest 时遇到了问题。 Here is what I have so far:
这是我到目前为止所拥有的:
NSInteger startPoint = 10;
for (int i=0; i<13; i++)
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[self getImageFromName:@"headshotsmile"] forState:UIControlStateNormal];
btn.frame = CGRectMake(startPoint, 10, 40, 40);
startPoint = startPoint + 40 + btn.frame.size.width;
[self.view addSubview:btn];
How do I get the rest of the images to show?如何获得要显示的图像的 rest?
CGPoint startPoint = CGPointMake(10, 10);
for (int i = 0; i < 13; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[self getImageFromName:@"headshotsmile"] forState:UIControlStateNormal];
btn.frame = CGRectMake(startPoint.x, startPoint.y, 40, 40);
startPoint.x += 40 + btn.frame.size.width;
if (i % 4 == 3) {
startPoint.x = 10;
startPoint.y += 40 + btn.frame.size.height;
}
[self.view addSubview:btn];
}
The key here is that whenever i
equals to 3 modulo 4, you simply move startPoint
to the beginning of the next line.这里的关键是每当
i
等于 3 模 4 时,您只需将startPoint
移动到下一行的开头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.