2012-06-01 45 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)];