水平显示图像/图标的最佳编程方法是什么?

时间:2010-07-15 09:37:27

标签: iphone objective-c

我正在尝试将图标/图像水平放置在旨在显示详细信息的视图中。每行的最大图片数量为6件,我希望有一种机制可以自动管理换行符或类似行。我怀疑这是一个解决这个问题的自定义单元格?

我在下面尝试了以下代码,但上面的图片在我重新加载视图时添加了另一个代码。此外,代码返回的视图不会调整单元格的高度。

-(UIImageView *)fillView{
collage = nil;
collage = [[[UIImageView alloc] initWithFrame:CGRectMake(11, 7, 0, 0)] autorelease];

int rowCounter = 0;
int colCounter = 0;
int nrOfPictures = [paymentImages count];

    //max 6 images per row
while (nrOfPictures > 0) {
    while (colCounter <= 6 && nrOfPictures != 0) {
        UIImageView *iv = [[UIImageView alloc] initWithImage:[paymentImages objectAtIndex:nrOfPictures-1]];
        CGRect frame = iv.frame;
        frame.origin.x = (frame.size.width + 4) * colCounter;
        frame.origin.y = (frame.size.height + 4) * rowCounter;
        iv.frame = frame;
        [collage addSubview:iv];
        [iv release];

        colCounter++;
        nrOfPictures--;
        if (colCounter > 6) {
            colCounter = 0;
            rowCounter++;
        }
    }
}   
return collage;

}

有人能指引我朝正确的方向前进吗?

最诚挚的问候 / / Christoffer

1 个答案:

答案 0 :(得分:2)

您可能想要查看此项目。 http://github.com/kirbyt/KTPhotoBrowser