2012-06-01 4 views
0

사진 배열이 포함 된 앱을 만듭니다. UIImageView 개체가 있고 배열의 이미지를 내 이미지 뷰로 표시하려고합니다. 어떻게해야합니까? 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

아니요 작동하지 않습니다. 이미지의 의미는 무엇입니까? – APRULE

0

당신은있는 UIScrollView에있는 UIImageView 객체를 추가 한 다음 즉 뷰에 스크롤있는 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)]; 
관련 문제