Ich habe eine UICollectionView
verwenden und Bilder in Zellen setzen. Ich möchte eine Zellgröße ist width = view/2
und hight = view/3
. und top margin =8
, right = 8
, left = 8
.Ich befestigte ein Bild bitte eins. Ich möchte das bitte ein Bild sehen.Wie setze ich UICollectionViewCell Größe
MEIN 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
ich viele Male und viele weitere Methoden versucht, aber Zelle wie angehängtem Bild nicht gesetzt. Bitte schlage vor, wie ich das machen kann. Thankyou
wie zwischen zwei Zellen einzustellen, Abstand? –
Verwenden Sie EdgeInset dafür. Gib UIEdgeInsetsMake (0, 5, 0, 5); –