4

I'm getting a headache by searching how to resize a cell (width and height) in an UICollectionViewController. With an UITableViewController there is the method :

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

But with UICollectionViewController I cannot find the method to do it programmatically.

I have an UICollectionViewCell but it is not there apparently.

How can I change the size of a cell in a UICollectionViewController?

Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113
xGoPox
  • 674
  • 8
  • 23

1 Answers1

5

Looks like you need to use a UICollectionViewFlowLayout and the UICollectionViewFLowLayoutDelegate and implement

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

Check out the Ray Wenderlich Tutorial: http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

hukir
  • 1,733
  • 1
  • 9
  • 13
  • 2
    Unfortunately, this method is called [before the cell is created](http://stackoverflow.com/questions/13750428/resize-uicollectionview-cells-after-their-data-has-been-set). So, it doesn’t work if you need to resize the cell based on varying content size. – johnnieb Oct 25 '13 at 23:39
  • Is there anyway to size cell based on the contents without doing tedious manual coding?? – Patrick Jackson Feb 13 '14 at 02:57
  • 1
    I don't think there is any way to do it completely automatically, but you can still get the benefit of auto layout. Here's an article with one way: http://blog.amyworrall.com/post/66085151655/using-auto-layout-to-calculate-table-cell-height – hukir Feb 13 '14 at 04:08