动态大小UICollectionView单元格 [英] Dynamic size UICollectionView cell

查看:107
本文介绍了动态大小UICollectionView单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)如何实现如图所示 UICollectionView

1) How can i achieve as shown in image with UICollectionView?

2)我试过 - (CGSize)collectionView:(UICollectionView *)collectionView布局:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath method&通过不同的大小,但它留下了细胞之间的空间。我可以清空这些空间吗?我想要不同的高度和每个单元格的宽度

2) I've tried -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath method & passed different sizes but it leaves out spaces between cells. Can i empty those spaces? I want different height & width for every cell

当前输出:

推荐答案

抱歉这是超级晚了......但也许这个将帮助那些尚未找到答案的人。
如果你有一个数组中的图像,你可以简单地参考图像大小并从那里调整单元格大小:

Sorry this is super late... But maybe this will help people who haven't found an answer yet. If you have your images in an array, you can simply reference the image size and make the adjustments to the cell size from there:

- (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); 
}

希望这会有所帮助..

Hope this helps..

这篇关于动态大小UICollectionView单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆