Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView adds top margin

I want to put a UICollectionView control that shows thumbs horizontally (only a single line of thumbs). For some reason the UICollectionView push the thumbs 44 pixels down, so the "0" height is actually "44". I assume it might be adding this space to consider the navigation bar height (I just assume). Since my UICollectionView is only on part of the screen, I don't want this margin. Is there a way to remove it?

like image 566
bashan Avatar asked Oct 16 '13 18:10

bashan


People also ask

How does UICollectionView work?

UICollectionView makes adding custom layouts and layout transitions, like those in Photos, simple to build. You're not limited to stacks and grids because collection views are customizable. You can use them to make circle layouts, cover-flow style layouts, Pulse news style layouts and almost anything you can dream up!

How do I make my UICollectionView scroll horizontal?

You need to reduce the height of UICollectionView to its cell / item height and select " Horizontal " from the " Scroll Direction " as seen in the screenshot below. Then it will scroll horizontally depending on the numberOfItems you have returned in its datasource implementation.

How do I add a header in collection view?

There are no section headers in the UICollectionView. So for your first task, you'll add a new section header using the search text as the section title. To display this section header, you'll use UICollectionReusableView .

What is Uicollectionviewflowlayout?

A layout object that organizes items into a grid with optional header and footer views for each section.


2 Answers

The issue may be in collection view's content insets. Try to add self.automaticallyAdjustsScrollViewInsets = NO; into view controller's viewDidLoad method.

like image 68
Sviatoslav Yakymiv Avatar answered Oct 02 '22 18:10

Sviatoslav Yakymiv


You can set this in the storyboard too.

Make sure you've selected the ViewController, and then untick "Adjust Scroll View Insets".

enter image description here

I haven't tested what this IB/Storyboard method does on iOS6 though. With the code method you need to check that the VC responds to the method:

if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) { self.automaticallyAdjustsScrollViewInsets = NO; } 
like image 40
siburb Avatar answered Oct 02 '22 19:10

siburb