简体   繁体   English

iOS中的集合视图动态单元格大小

[英]Collection View Dynamic Cell size in ios

How can I achieve this by Collection view?? 如何通过收藏夹视图实现此目的? I have tried sizeForItemAtIndexPath but it didn't work as i want? 我已经尝试过sizeForItemAtIndexPath,但是没有按我的意愿工作?

Can anyone suggest me how to do it?? 谁能建议我该怎么做?

在此处输入图片说明

Edit: I have done: 编辑:我已经完成:

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

{ {

if (indexPath.item==0)
{

     return CGSizeMake(200,200);
}
else
{

    return CGSizeMake(90,90);

}

and got response : 并得到回应:

在此处输入图片说明

use a UICollectionViewDelegateFlowLayout method to specify the size you want for each cell. 使用UICollectionViewDelegateFlowLayout方法指定每个单元格所需的大小。 This method is: 该方法是:

Objc: Objc:

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

Swift 迅速

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

  }

Define the CGSize you want and your cells will take width and height you define. 定义所需的CGSize,单元格将采用您定义的宽度和高度。

Your UIViewController must implement UICollectionViewDelegateFlowLayout Protocol 您的UIViewController必须实现UICollectionViewDelegateFlowLayout协议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM