2011-04-06 2 views

Répondre

1

Vous pouvez utiliser un UIScrollView pour cette ...

Chaque élément de votre grille est un UIImageView que vous ajoutez à votre comme subviews UIScrollView.

Le code suivant peut être inséré dans viewDidLoad à l'intérieur de votre contrôleur de vue et suppose que vous avez configuré votre UISCrollView dans le constructeur d'interface, sinon vous devrez allouer votre vue de défilement à viewDidLoad.

Le code ajoutera un nombre variable d'éléments d'image à un UIScrollView avec 4 colonnes.

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 également mettre en œuvre la même solution par moi-même – nehal

+0

Comment gérez-vous la sélection des éléments? – ADude

Questions connexes