【问题标题】:How to customise collection view cell as per the images如何根据图像自定义集合视图单元格
【发布时间】:2015-04-22 13:31:21
【问题描述】:

下面是我的代码。我可以加载,但两个单元格之间有一些空间。如何避免。

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [dashBoard_img count];
}
- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UIImage * image = [UIImage imageNamed:[dashBoard_img objectAtIndex:indexPath.row]];
    return image.size;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5.0, 5.0, 5.0, 5.0);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewFlowLayout *)collectionViewLayout
interitemSpacingForSectionAtIndex:(NSInteger)section {
    return 2.0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FMMosaicCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[FMMosaicCellView reuseIdentifier] forIndexPath:indexPath];
   // float horizontal = 8.0;
    //float vertical = 15.0;
    UIImage *image = [UIImage imageNamed:[dashBoard_img objectAtIndex:indexPath.row]];
    cell.imageView.frame = CGRectMake(cell.imageView.frame.origin.x, cell.imageView.frame.origin.y, image.size.width, image.size.height);
//    cell.imageView.frame = CGRectMake(horizontal, cell.imageView.frame.origin.y, image.size.width, image.size.height);
    cell.imageView.image = image;
    return cell;
}

【问题讨论】:

    标签: ios objective-c iphone uicollectionview


    【解决方案1】:

    也许你必须避免插入。

    输入:return UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);

    代替:return UIEdgeInsetsMake(5.0, 5.0, 5.0, 5.0);

    【讨论】:

      【解决方案2】: