简体   繁体   中英

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?

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. This method is:

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.

Your UIViewController must implement UICollectionViewDelegateFlowLayout Protocol

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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