2011-04-06 3 views

답변

1

당신은 이것에 대한 UIScrollView을 사용할 수 있습니다 ...

그리드의 각 항목은 당신이 당신의 UIScrollView에 파단으로 추가 할 UIImageView이다.

다음 코드는보기 컨트롤러 안의 viewDidLoad에 삽입 할 수 있으며 인터페이스 작성기에 UISCrollView를 설정했다고 가정합니다. 그렇지 않으면 viewDidLoad 안에 스크롤보기를 할당해야합니다.

코드는 4 개의 열이있는 UIScrollView에 가변 개수의 이미지 항목을 추가합니다.

UIImageView *imageView = nil; 

//The x and y view location coordinates for your menu items 
int x = 0, y = 0; 

//The number of images you want 
int numOfItemsToAdd = 10; 

//The height and width of your images are the screen width devided by the number of columns 
int imageHeight = 320/4, imageWidth = 320/4; 

int numberOfColumns = 4; 

//The content seize needs to refelect the number of items that will be added 
[scrollView setContentSize:CGSizeMake(320, imageHeight*numOfItemsToAdd]; 
for(int i=0; i<numOfItemsToAdd; i++){ 
    if(i%numberOfColumns == 0){//% the number of columns you want 
     x = 0; 
     if(i!=0) 
      y += imageHeight; 
    }else{ 
     x = imageHeight; 
    } 
    imageView = [[UIImageView alloc] initWithFrame: CGRectMake(x, y, imageWidth, imageHeight)]; 

    //set the center of the image in the scrollviews coordinate system 
    imageView.center = CGPointMake(x, y); 

    imageView.image = [UIImage imageNamed:@"my_photo.png"]; 

    //Finaly add the image to the scorll view 
    [scrollView addSubview:imageView]; 
+0

thnx.i도 동일한 해결책을 구현합니다. – nehal

+0

항목 선택은 어떻게 처리합니까? – ADude

관련 문제