0

我创建了一个包含一系列照片的应用程序。我有一个 UIImageView 对象,我想将数组中的图像显示到我的 imageview 中。我怎样才能做到这一点?

我的数组声明:

     photoArray = [[NSMutableArray alloc] init];
     PhotoItem *photo1 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"1.jpg"] name:@"roy rest"  photographer:@"roy"];
     PhotoItem *photo2 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"2.jpg"] name:@"roy's hand" photographer:@"roy"];
     PhotoItem *photo3 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"3.jpg"] name:@"sapir first" photographer:@"sapir"];
     PhotoItem *photo4 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"4.jpg"] name:@"sapir second" photographer:@"sapir"];
     [photoArray addObject:photo1];
     [photoArray addObject:photo2];
     [photoArray addObject:photo3];
     [photoArray addObject:photo4];

另一个问题:我如何编写一个代码来创建一个 uiimageview 作为我数组中对象的编号?

谢谢!!

4

2 回答 2

0

请参考下面,让我知道它是否有用?

for(PhotoItem *photoItem in photoArray){
        UIImageView *imgView = [[UIImageView alloc] initWithImage:photoItem.imageProperty];
     [self.view addSubview:imgView];
    }
于 2012-06-01T11:19:16.757 回答
0

您可以将 UIImageView 对象添加到 uiscrollView,然后添加 uiscrollView 对象,即滚动到视图...

    int y = 10;
    for (UIImage *img in array) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, y,200, 400)];
        [imgView setImage:img];
        [scroll addSubview:imgView];
        y = y + imgView.frame.size.height + 5;
    }
    [scroll setContentSize:CGSizeMake(300, y)];
于 2012-06-01T11:23:21.780 回答