Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sncf-connect-tech/vscollectionviewcellinsetflowlayout
Apply margins to UICollectionViewCells
https://github.com/sncf-connect-tech/vscollectionviewcellinsetflowlayout
inset margin swift uicollectionview uicollectionviewcell uicollectionviewflowlayout
Last synced: about 2 months ago
JSON representation
Apply margins to UICollectionViewCells
- Host: GitHub
- URL: https://github.com/sncf-connect-tech/vscollectionviewcellinsetflowlayout
- Owner: sncf-connect-tech
- License: mit
- Created: 2017-04-10T15:55:13.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-04T09:24:18.000Z (over 7 years ago)
- Last Synced: 2024-09-20T02:02:09.703Z (4 months ago)
- Topics: inset, margin, swift, uicollectionview, uicollectionviewcell, uicollectionviewflowlayout
- Language: Shell
- Homepage:
- Size: 218 KB
- Stars: 8
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VSCollectionViewCellInsetFlowLayout
VSCollectionViewCellInsetFlowLayout, based on UICollectionViewFlowLayout, enables to add margins on cells
## Get Started
Based on the same principle of ```collectionView(_:layout:insetForSectionAt:)```, VSCollectionViewCellInsetFlowLayout provides a delegate method to define margins on ```UICollectionViewCell```
### Setup
Instanciate a VSCollectionViewCellInsetFlowLayout then set it as the layout of the collectionView:
```swift
collectionView.collectionViewLayout = VSCollectionViewCellInsetFlowLayout()
```VSCollectionViewCellInsetFlowLayout is using the collectionview delegate if this one conforms to ```VSCollectionViewDelegateCellInsetFlowLayout```.
Implement ```collectionView(_:layout:insetForItemAt:)```:
```swift
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à !
## Notes
If flowLayout scrollDirection is **vertical**:
- **inset.top** offsets the item vertically, **inset.bottom** offsets the next item vertically or offsets contentSize if no more cell. All next items and contentSize are also offset vertically by the specified margins.
- **inset.left** offset the item horizontally and subtracts the value from the cell width, **inset.right** updates the width of the cell without offsets its origin. Others cells and contentSize are **not** impacted by the specified margins.If flowLayout scrollDirection is **horizontal**:
- **inset.left** offsets the item horizontally, **inset.right** offsets the next item horizontally or offsets contentSize if no more cell. All next items and contentSize are also offset horizontally by the specified margins.
- **inset.top** offset the item vertically and subtracts the value from the cell height, **inset.bottom** updates the height of the item without offsets its origin. Others items and contentSize are **not** impacted by the specified margins.## Installation
### Installation with CocoaPods
Copy and paste the following lines to your PodFile file:
source 'https://github.com/CocoaPods/Specs.git'
pod 'VSCollectionViewCellInsetFlowLayout'### Manual installation
- [Download](https://github.com/voyages-sncf-technologies/VSCollectionViewCellInsetFlowLayout/releases) the last release of VSCollectionViewCellInsetFlowLayout.
- Import the folder *VSCollectionViewCellInsetFlowLayout* into your project.### Sample
You may download the project to have a look at the integrated sample.
## Credits
VSCollectionViewCellInsetFlowLayout is owned and maintained by [Voyages-sncf.com](http://www.voyages-sncf.com/).
VSCollectionViewCellInsetFlowLayout was originally created by [Gwenn Guihal](https://github.com/myrddinus).
## License
VSCollectionViewCellInsetFlowLayout is released under the MIT license.