Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting minimum line spacing in collectionView

I'm trying to set the minimum line spacing using swift in my collectionViewController, but i can't seem too find the method i need to use. I need this to be programmatically since i need to change this dynamically depending on the selectedSegmentedIndex. How can i change the minimum line spacing programmatically?

i've tried to add the UICollectionViewFlowLayout, but cant since it's a UICollectionViewController.

i guess i need to use something like.

collectionView:layout:minimumLineSpacingForSectionAtIndex:
like image 372
Peter Pik Avatar asked Oct 14 '14 08:10

Peter Pik


People also ask

What is minimum line spacing?

method, the flow layout uses the value in this property to set the spacing between lines in a section. 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.

How do I change the spacing between cells in collection view?

I have found very easy way to configure spacing between cells or rows by using IB. Just select UICollectionView from storyboard/Xib file and click in Size Inspector as specified in below image. For configuring space programatically use following properties. 1) For setting space between rows.

What is UICollectionView flow layout?

Overview. A flow layout is a type of collection view layout. Items in the collection view flow from one row or column (depending on the scrolling direction) to the next, with each row containing as many cells as will fit. Cells can be the same sizes or different sizes.

Do CollectionView use cells?

CollectionView has no concept of cells. Instead, a data template is used to define the appearance of each item of data in the list. CollectionView automatically utilizes the virtualization provided by the underlying native controls.


2 Answers

Swift 4.2

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

        return 10
    }
like image 114
Lakhdeep Singh Avatar answered Oct 12 '22 23:10

Lakhdeep Singh


Make your UICollectionViewController conform to the protocol UICollectionViewDelegateFlowLayout.

The method you're looking for is:

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;

like image 37
Rowan Jones Avatar answered Oct 13 '22 01:10

Rowan Jones