UICollectionview cell之间有空隙,请问怎么解决

发布于 2022-09-05 06:35:24 字数 1613 浏览 46 评论 0

前辈们好 请教下
我有个一个collectionview a section水平摆4个cell,b section水平摆3个cell,同一个section的cell互相之间都没有间距,sectionInset也是(0,0,0,0)

cell的size是这样

+(CGSize)cellSizeWithEachLineCount:(NSInteger)count{
    CGFloat w = screenWidth / (float)count;
    CGFloat h = 80;
    return CGSizeMake(w,h);
}

UICollectionViewDelegateFlowLayout协议如下:

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

    UIEdgeInsets inset = UIEdgeInsetsZero;
    switch (section) {
        case 0:
            inset = UIEdgeInsetsMake(0, 0, 0, 0);
            break;
        case 1:
            inset = UIEdgeInsetsMake(0, 0, 0, 0);
            break;
        case 2:
            inset = UIEdgeInsetsMake(0, 0, 0, 0);
            break;
        case 3:
            inset = UIEdgeInsetsMake(8, 0, 0, 0);
            break;
        default:
            break;
    }
    
    return inset;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

    return 0.0;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{

    return 0.0;
}

但a section有间隙,b section没有,如下图(待付款与待发货之间,待收货与待评价之间)
图片描述

请问怎么回事?应该怎么解决?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼中杀气 2022-09-12 06:35:25

把背景调成白色就看不出来了...233333

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文