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
comment configurer entre deux cellules espacement? –
utilisez edgeInset pour cela. Donne UIEdgeInsetsMake (0, 5, 0, 5); –