创建多个图像视图,如照片应用程序iphone sdk

时间:2009-10-26 20:08:30

标签: iphone

如何创建包含多个图像的视图,类似于iPhone上的照片应用程序?

感谢

3 个答案:

答案 0 :(得分:3)

因此,如果您想要一个4乘4的图片网格(例如20x20),您可以使用滚动视图并添加UIImageViews,如

UIScrollView *s= [[UIScrollView alloc] initWithFrame:someFrame]
int position x=10;
int position y=10;
for(int i=1; i<=pictures.count; i++)
{
    UIImageView *image= [[UIImageView alloc] initWithFrame:CGRectMake(x,y,20,20)]
    image.image=[UIImage imageNamed:..] //initialize the image for the view
    [s addSubview:image];
    if(i%4==0) //means you need to start a new row
     {
          y+=20; //you can tweak this to make it look how you like
          x=10; //come back to the beggining
     }
   else
      x+=10; //again tweak this to make it "look" right

}

答案 1 :(得分:1)

我的标准答案:查看Three20 project中的TTPhotoViewController

  

TTPhotoViewController模拟Apple的   照片应用程序的所有电影n'   捏喜悦。你可以提供自己的   “照片来源”,有效   类似于使用的数据源   UITableView的。与Apple的照片不同   应用程序,它不仅限于存储的照片   本地。您的照片可以加载   来自网络,以及长名单   照片可以逐步加载。

答案 2 :(得分:0)

对我来说效果更好(Daniel的代码修改):

UIScrollView *s = [[UIScrollView alloc] initWithFrame:someFrame];
int numOfColumns = 4;
int numOfRows = imagesArray.count/numOfColumns+1;
int space = 10;
int width = (s.frame.size.width-(numOfColumns+1)*space)/numOfColumns;
int height = width;
int x = space;
int y = space;
for (int i=1; i<=imagesArray.count; i++) {
    UIImageView *image= [[UIImageView alloc] initWithFrame:CGRectMake(x,y,width,height)];
    image.image = [UIImage imageWithData:[imagesArray objectAtIndex:i-1]];
    [s addSubview:image];
    [image release];
    if (i%numOfColumns == 0) {
        y += space+height;
        x = space;
    } else {
        x+=space+width;
    }
}
int contentWidth = numOfColumns*(space+width)+space;
int contentHeight = numOfRows*(space+height)+space;
[s setContentSize:CGSizeMake(contentWidth, contentHeight)];
[self.view addSubview:s];

imagesArrayArray

NSData