TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Aug 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Gwenn Guihal.
VSCollectionViewCellInsetFlowLayout, based on UICollectionViewFlowLayout, enables to add margins on cells
Based on the same principle of collectionView(_:layout:insetForSectionAt:)
, VSCollectionViewCellInsetFlowLayout provides a delegate method to define margins on UICollectionViewCell
Instanciate a VSCollectionViewCellInsetFlowLayout then set it as the layout of the collectionView:
collectionView.collectionViewLayout = VSCollectionViewCellInsetFlowLayout()
VSCollectionViewCellInsetFlowLayout is using the collectionview delegate if this one conforms to VSCollectionViewDelegateCellInsetFlowLayout
. Implement collectionView(_:layout:insetForItemAt:)
:
extension ViewController : VSCollectionViewDelegateCellInsetFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForItemAt indexPath: IndexPath) -> UIEdgeInsets {
if indexPath.item == 0 {
return UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
}
return UIEdgeInsets.zero
}
}
Et voilà !
If flowLayout scrollDirection is vertical:
If flowLayout scrollDirection is horizontal:
You may download the project to have a look at the integrated sample.
VSCollectionViewCellInsetFlowLayout is owned and maintained by Voyages-sncf.com.
VSCollectionViewCellInsetFlowLayout was originally created by Gwenn Guihal.
VSCollectionViewCellInsetFlowLayout is released under the MIT license.