Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set minimum contentsize for UICollectionView

I want to be able to set the minimum height of the content size within a UICollectionView, so I can hide/show a UISearchbar, similar to the way it's done on iBooks.

However, I don't want to subclass the layout as I want to keep the standard vertical layout for a UICollectionView.

any ideas?

like image 702
Adam Carter Avatar asked Feb 17 '23 22:02

Adam Carter


1 Answers

You can do this by subclassing UICollectionViewFlowLayout and overriding the method

-(CGSize)collectionViewContentSize
{ //Get the collectionViewContentSize
     CGSize size = [super collectionViewContentSize];
     if (size < minimumSize) return minimumSize;
     else return size;
}

Edit: I just realized you said you didn't want to subclass the layout. Anyway, I subclassed UICollectionViewFlowLayout and only modified the collectionViewContentSize method. It kept the standard vertical layout for me.

Edit: https://stackoverflow.com/a/14465485/2017159. Here it says UICollectionViewFlowLayout only supports one direction (vertical or horizontal), so it should be fine?

like image 82
khangsile Avatar answered Feb 28 '23 15:02

khangsile