UICollectionVIew: How can I remove the space on top first cell’s row?

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)];

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

Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself.

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];

Leave a Comment