我已经使用UICollectionView
并在单元格中设置图像。我想要的单元格大小是width = view/2
和hight = view/3
。和顶部margin =8
,right = 8
,left = 8
。我附上一张图片请参阅。我想喜欢这个,请看一张图片。如何设置UICollectionViewCell大小
MY 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
我试图多次,有更多的方法用于但不设置像附加图像细胞。请建议我如何做到这一点。三江源
如何在两个小区之间设定间距? –
使用edgeInset。给UIEdgeInsetsMake(0,5,0,5); –