Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand collectionview cell to full screen [closed]

I'm trying to print the image on fullscreen I used UICollectionViewDelegateFlowLayout here my code is

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let itemWidth = collectionView.bounds.width
        let itemHeight = collectionView.bounds.height
        return CGSize(width: itemWidth, height: itemHeight)
    }

but it doesn't show the content on full screen it makes space from top and bottom

like image 313
AfterCoder Avatar asked Oct 31 '16 16:10

AfterCoder


1 Answers

If you want to increase cell size to fit to your screen you can use this method.

Objective-C

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}

Swift

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        //For entire screen size
        let screenSize = UIScreen.main.bounds.size
        return screenSize
        //If you want to fit the size with the size of ViewController use bellow
        let viewControllerSize = self.view.frame.size
        return viewControllerSize

        // Even you can set the cell to uicollectionview size
        let cvRect = collectionView.frame
        return CGSize(width: cvRect.width, height: cvRect.height)


    }
like image 177
Syed Qamar Abbas Avatar answered Nov 15 '22 22:11

Syed Qamar Abbas