4

通过搜索如何在UICollectionViewController中调整单元格大小(宽度和高度),我感到头痛。随着UITableViewController有方法:UICollectionViewController如何调整单元格大小?

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

但随着UICollectionViewController我找不到这样做编程的方法。

我有一个UICollectionViewCell,但它并不明显。

如何更改UICollectionViewController中单元格的大小?

回答

5

看起来你需要使用一个UICollectionViewFlowLayout和UICollectionViewFLowLayoutDelegate和实施

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

退房雷Wenderlich教程: http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

+2

不幸的是,这种方法被称为[创建细胞之前( http://stackoverflow.com/questions/13750428/resize-uicollectionview-cells-after-their-data-has-been-set)。因此,如果您需要根据不同的内容大小来调整单元格大小,则它不起作用。 – johnnieb

+0

无论如何根据内容大小的细胞没有做繁琐的手动编码? – Patrick

+1

我不认为有任何方法可以完全自动完成,但您仍然可以获得自动布局的好处。这里有一个方法的文章:http://blog.amyworrall.com/post/66085151655/using-auto-layout-to-calculate-table-cell-height – hukir

相关问题