我是否需要编写一个自定义的UICollectionViewLayout
问题描述:
我有一个收集视图的想法,当只有一些项目时将项目保持居中,然后回落到传统的垂直流程。 下面是我如何扩展图片,因为我需要更多的项目。我是否需要编写一个自定义的UICollectionViewLayout
1.这是acumblisable与通用UICollectionViewFlowLayout
?
2.如果没有你有任何建议如何做到这一点与自定义布局?
答
一个想法可能是管理您的模型,以便能够将空的UICollectionViewCell放到需要的位置。
例如:
- (void)setMyModel:(NSArray*)array
{
NSMutableArray myNewModel = [NSMutableArray array];
if (array.count < 5){
[self addEmptyLine:myNewModel]
}
int nbOfLine = (int)(array.count/5);
int nbOfCellLastLine = ((array.count/5) - nbOfLine)*5;
// add nbOfLine * 5 object in your array
// add your last line
[self addLineWithNbOfCell:nbOfCellLastLine andArray:array];
}
这只是一个快速的想法,但可以工作。
+0
我正在考虑做这样的事情,但我不喜欢在我的模型中有'空白'的想法。我想尝试保持分离。 –
我的第一个想法是'contentInset'有很多东西吗? –