Vahagn Yeghoyan
Vahagn Yeghoyan

Reputation: 53

How to regulate CollectionViewCell size, by code or by storyBoard(CollectionView is inside of TableView)

Runned Project //My CollectionView sizes //My TableView sizes

I have collectionView Inside UITableViewCell, and in UICollectionViewCell I have UImageView, when I run the project there are some free space, which i don't want: how can I fix it(by code or by storyboard - it doesn't matter)

Upvotes: 0

Views: 39

Answers (1)

Mohd Sultan
Mohd Sultan

Reputation: 232

You should fix it by code. You can manage space between two UICollectionView cells by using UICollectionViewDelegateFlowLayout methods.

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: collectionView.frame.width, height: collectionView.frame.height)
}

Provide the cell height and width in the above method.

     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 0
}

The above method use for a vertically scrolling grid, this value represents the minimum spacing between successive rows. For a horizontally scrolling grid, this value represents the minimum spacing between successive columns.

Upvotes: 1

Related Questions