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:
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.
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.
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.
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.
Swift 4.2
func collectionView(_ collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 10
}
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With