Hilaj S L
Hilaj S L

Reputation: 2046

how to set cell size of a UICollectioView programmatically in ios

I have collectionView and tableView. When I select the first cell in the tableview, 6 cells are shown in the collectionView. And when I select the second cell collectionView should show 4 cells. Now I need to increase the size of the collectionView cell when I click on the second cell of the tableview.

Upvotes: 0

Views: 414

Answers (2)

Satyanarayana
Satyanarayana

Reputation: 1067

 - (CGSize)collectionView:(UICollectionView *)collectionView
                      layout:(UICollectionViewLayout *)collectionViewLayout
      sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        CGSize size;
        CGRect bounds = [[UIScreen mainScreen] bounds];
        double bWidth = (bounds.size.width/320)* 200 ; // 200 is your cell width which given in xib
        double bheight = (bWidth/320)* 250 // 250 is your cell height which given in xib;
        size = CGSizeMake(bWidth, bheight);

        return size;
    }

Upvotes: 0

sohil
sohil

Reputation: 848

use this method and check it selected cell of table

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  iF(cell==secound)
  {
    return CGSizeMake(100, 100);
  }
  else
  {
    return CGSizeMake(100, 50);
  }
}  

and

@interface MyViewController () <UICollectionViewDelegateFlowLayout>

Upvotes: 1

Related Questions