2012-06-01 50 views
0

我创建了一个包含照片数组的应用程序。 我有一个UIImageView对象,我想从数组中显示图像到我的imageview。 我该怎么做?如何使用uiimageview查看图像中的图像

我的数组声明:

 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在我的数组对象的数目的代码?

谢谢!!

+0

你怎么想展示的形象呢?在单个图像视图或4个图像视图中? – Ilanchezhian

回答

0

请在下面引用,让我知道它有用吗?

for(PhotoItem *photoItem in photoArray){ 
     UIImageView *imgView = [[UIImageView alloc] initWithImage:photoItem.imageProperty]; 
    [self.view addSubview:imgView]; 
    } 
+0

不,这是行不通的。 imagePropery的含义是什么? – APRULE

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)];