0

J'ai utilisé un UICollectionView et j'ai défini des images dans des cellules. Je veux une taille de cellules est width = view/2 et hight = view/3. et en haut margin =8, right = 8, left = 8 .J'ai attaché une image s'il vous plaît voir ceux. Je veux aimer ceci s'il vous plaît voir une image.Comment régler la taille UICollectionViewCell

MON CODE

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
return img_ary.count; 
} 


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
static NSString *identifier = @"Cell"; 


category_cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 
cell.img_view.image = [UIImage imageNamed:[img_ary objectAtIndex:indexPath.row]]; 


return cell; 
} 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 
// [self performSegueWithIdentifier:@"showRecipeDetails" sender:self]; 


} 

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ 
return UIEdgeInsetsMake(0, 0, 0, 0); //top, left, bottom, right); 

} 

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 
CGFloat widthOfCell =(self.view.frame.size.width-30)/2; 
CGFloat heightOfCell =(self.view.frame.size.height-30)/4; 
CGSize returnValue = CGSizeMake(widthOfCell, heightOfCell); 
returnValue.height += 5; 
returnValue.width += 5; 
return returnValue; 

} 

IMAGE: I want to likes this please see

J'ai essayé de nombreuses fois et bien d'autres méthodes sont utilisées mais pas régler la cellule comme l'image ci-joint. S'il vous plaît suggérer comment je peux le faire. Thankyou

Répondre

1

Avez-vous essayé

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;{ 

    CGSize defaultSize = CGSizeMake((_collectionViewSongs.frame.size.width/2)-10, (_collectionViewSongs.frame.size.width/2)-10); 


    return defaultSize; 
} 
+0

comment configurer entre deux cellules espacement? –

+0

utilisez edgeInset pour cela. Donne UIEdgeInsetsMake (0, 5, 0, 5); –

0

donner gauche, à droite, en haut et en bas 0 à votre vue collection

utilisation ci-dessous la méthode de vue de la collecte

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 
int width = (collectionView.frame.size.width/2)-8; 
int height = (collectionView.frame.size.height/3)-8; 
return CGSizeMake(width, height);} 
+0

comment définir entre deux cellules d'espacement? –

+0

sélectionnez votre collection et obtenez l'inspecteur de taille que vous trouvez "Espacement minimum" pour Cell et pour Ligne. vous pouvez changer l'espacement d'ici –