1)如何使用UICollectionView
实现如图所示
2)我尝试过-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
方法&传递了不同的大小,但它省略了单元格之间的空格。我能清空那些空间吗?我希望每个单元格都有不同的高度和宽度
电流输出:
。
发布于 2014-08-13 07:45:08
抱歉这么晚了..。但也许这会帮助那些还没有找到答案的人。如果您的图像在数组中,您可以简单地引用图像大小,并从那里对单元大小进行调整:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image = [imageArray objectAtIndex:indexPath.row];
//You may want to create a divider to scale the size by the way..
return CGSizeMake(image.size.width, image.size.height);
}
希望这能帮上忙..
发布于 2014-05-26 21:53:04
也许这个布局可以满足你的需求。请看一下这个项目:https://github.com/betzerra/MosaicLayout
我不确定100%它是否能完全满足您的需求,但在最坏的情况下,它可能会帮助您编写自定义的UICollecionViewFlowLayout (这是实现目标的唯一方法)
发布于 2014-05-20 21:01:31
你不能用标准的UICollectionViewFlowLayout
实现像你问题中那样的结果,在它的基础实现中(没有子类化)创建一个网格布局。
要获得您想要的内容,您应该创建自己的UICollectionViewLayout
(或者UICollectionViewFlowLayout
)子类,在这个子类中,您可以执行将每个项目放置在正确框架中所需的所有计算。
看看这里有没有great tutorial,这里有something similar to what you want。
https://stackoverflow.com/questions/23760275
复制相似问题