Skip to content

Repository files navigation

FlexibleCollectionViewController

LanguageVersionLicensePlatform

Swift library of generic collection view controller with external data processing of functionality, like determine cell's reuseIdentifier related to indexPath, configuration of requested cell for display and cell selection handler etc

Example

Initialisation with configuration

_flexibleCollectionVC =FlexibleCollectionViewController(collectionViewLayout:CustomFlowLayout(), configuration:CollectionConfiguration(userInteractionEnabled:true, showsHorizontalScrollIndicator:false, isScrollEnabled:true, multipleTouchEnabled:false, backgroundColor:.clear))

Cell and supplementary view registering

_flexibleCollectionVC.register(UICollectionViewCell.self, forCellWithReuseIdentifier:"UICollectionViewCell")
_flexibleCollectionVC.registerSupplementaryView(UIHeaderImageCollectionView.self, kind:.header, reuseIdentifier:UIHeaderImageCollectionView.reuseIdentifier)

Requesting indentifier of cell for specific indexPath

_flexibleCollectionVC.requestCellIdentifier ={ value inreturn"UICollectionViewCell"}

Requesting indentifier of supplementary view for specific indexPath

_flexibleCollectionVC.requestSupplementaryIdentifier ={ value inreturnUIHeaderImageCollectionView.reuseIdentifier
}

Configuration of input cell with related data to indexPath

_flexibleCollectionVC.configureCell ={(cell:UICollectionViewCell, data:CollectionImageCellData?, indexPath:IndexPath)inguardlet data = data else{returnfalse}
cell.backgroundColor = data.color
returntrue}

Configuration of supplementary view with related kind and data to indexPath

_flexibleCollectionVC.configureSupplementary ={(view:UICollectionReusableView, kind:SupplementaryKind, data:CollectionImageCellData?, indexPath:IndexPath)iniflet view = view as?UIHeaderImageCollectionView,let data = data {
view.text = data.category
returntrue}returnfalse}

Process cell selection to related indexPath

_flexibleCollectionVC.cellDidSelect ={ value inreturn(deselect:true, animate:true)}

Estimate cell size

_flexibleCollectionVC.estimateCellSize ={ value inguardlet layout = value.1as?UICollectionViewFlowLayoutelse{returnnil}letcol:CGFloat=3letwidth= value.0.bounds.width-(layout.sectionInset.left+layout.sectionInset.right)letside=round(width/col)-layout.minimumInteritemSpacing
returnCGSize(width: side, height: side)}

Put predefined cells in generated order related to ListGenerator

_flexibleCollectionVC.setData(getData())

Requirements

Swift 3 or above

Installation

FlexibleCollectionViewController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod"FlexibleCollectionViewController"

Author

Pilipenko Dima, dimpiax@gmail.com

License

FlexibleCollectionViewController is available under the MIT license. See the LICENSE file for more info.

About

Generic collection view controller with external data processing

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages