-1

I have a collectionview with custom collectionviewcell. I want to make a gallery that only one image display on the screen at any time. What i have to do ? Here is my code :

[myCollectionView registerClass:[myCustomCollectionViewCell class] forCellWithReuseIdentifier:"myIdentifier"];

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    myCustomCollectionViewCell *cell = (myCustomCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"myIdentifier" forIndexPath:indexPath];
    cell.layer.masksToBounds=NO;
    cell.imageView.image = [UIImage imageNamed:@"image"];
    return cell;

}
Saman
  • 503
  • 4
  • 18
  • 1
    you need to give frame in sizeForItemAtIndexPath which you want and enable the pagination property of uicollectionview, show some effort from your side also otherwise no one is free here to write whole code for you. check below code of Neha Gupta and try to implement as per your requirment – Hardik Thakkar Jul 12 '18 at 12:37
  • that's right thank you.@HardikThakkar – Saman Jul 14 '18 at 05:51

1 Answers1

1

First, register your collection view class like below

[yourCollectionView registerClass:[yourCustomCollectionViewCell class] forCellWithReuseIdentifier:"yourIdentifier"]; 

Second, implement collection view datasource method

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    yourCustomCollectionViewCell *cell = (yourCustomCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"yourIdentifier" forIndexPath:indexPath];
    cell.layer.masksToBounds=NO;
    cell.imageView.image = [UIImage imageNamed:@"yourImageName"];
    return cell;

}

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

    // update size accordingly
    return CGSizeMake(100,100);
}
Neha Gupta
  • 539
  • 3
  • 13