如何删除顶部第一个单元格行上的空格

如何删除顶部第一个单元格行上的空格

本文介绍了UICollectionVIew:如何删除顶部第一个单元格行上的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Interface Builder中有这种安排,所有属性都设置为零。

I have this arrangement in Interface Builder, All properties are set to zero.

然而,当我在设备和模拟器上运行它时,它看起来像这样

However, when I run it on both device and simulator it appears like this

单元格上方的空间来自哪里?

Where is the space above the cells come from?

所以我尝试在这样的代码中为UICollectionViewFlowLayout设置这些属性

So I try to set these properties for UICollectionViewFlowLayout in code like this

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.headerReferenceSize = CGSizeZero;
    layout.footerReferenceSize = CGSizeZero;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.itemSize = CGSizeMake(103, 119);

    self.calendarView.collectionViewLayout = layout;

但我没有运气。

我该怎样摆脱那个空间?
谢谢。

How can I get rid of that space?Thanks.

推荐答案

UICollectionView是UIScrollView类的后代,它具有 contentInset property,设置-20 top inset修复问题

UICollectionView is descendant of UIScrollView class which has contentInset property, setting -20 top inset fixes the problem

[self.calendarView setContentInset:UIEdgeInsetsMake(-20, 0, 0, 0)];

然而,问题来自UIViewController的 automaticAdjustsScrollViewInsets 属性。
通过文档:

However, the problem comes from UIViewController's automaticallyAdjustsScrollViewInsets property.By documentation:

这就是我们为状态栏调整内容插入的原因。最好禁用自动调整而不是手动设置的值,这与结果图片中的不匹配。

That's why we get adjusted content insets for status bar. It's better to disable automatically adjusting than manually set value which doesn't match in result picture.

[self setAutomaticallyAdjustsScrollViewInsets:NO];

这篇关于UICollectionVIew:如何删除顶部第一个单元格行上的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:50