【问题标题】:How to remove extra space from bottom in collection view in iOS?如何在 iOS 的集合视图中从底部删除多余的空间?
【发布时间】:2016-01-25 03:30:45
【问题描述】:

我有一个集合视图,其中我有一个单元格。在故事板上单元格的高度等于集合视图的高度。但是当我运行它时它会显示底部空间。请告诉我如何删除它.我已经使用以下代码来删除它。

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {

    [self setAutomaticallyAdjustsScrollViewInsets:NO];

    // return UIEdgeInsetsMake(0,8,0,8);  // top, left, bottom, right
    if (collectionView==self.album_collection_view)
    {
        return UIEdgeInsetsMake(0,10,0,10);

    }// top, left, bottom, right
    else

        return  UIEdgeInsetsMake(0,10,0,10);
}

请告诉如何删除它?

【问题讨论】:

  • 你能把你设置UICollectionViewLayout的代码贴出来吗?

标签: ios objective-c xcode uicollectionview


【解决方案1】:

我假设只有一行单元格。如果是这样,您可以尝试在 collectionView:cellForItemAtIndexPath: 中设置单元格高度。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    ...
                                                                                                    
    CGRect newFrame = cell.frame;
    newFrame.size.height = CGRectGetHeight(collectionView.frame);
    cell.frame = newFrame;                                                                                               
                                                                                                    
    return cell;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多