开发者

Problem in photo gallery

开发者 https://www.devze.com 2023-03-11 21:42 出处:网络
On the iPhone I would like to display images of size 60 * 60 at a time, with 3 of them on each row. I\'ve managed to get the first row with 3 images, but I\'m having trouble with the rest. Here is wha

On the iPhone I would like to display images of size 60 * 60 at a time, with 3 of them on each row. I've managed to get the first row with 3 images, but I'm having trouble with the rest. Here is what I have so far:

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];
开发者_开发技巧}        

this code is showing only 8 images while the number of images is 10.


I think you want...

i % 4 == 0

The mod will be 0 for every 4 items.

0

精彩评论

暂无评论...
验证码 换一张
取 消