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

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

问题描述

1) 如何使用 UICollectionView 实现如图所示的效果?

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

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

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

希望这会有所帮助..

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

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