CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
| TestsTested | ✓ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Oct 2017 |
| SwiftSwift Version | 4.0 |
| SPMSupports SPM | ✗ |
Maintained by ro6lyo.
UICollectionViewGallery has been implemented as UICollectionView extensions, all public functions are
accesible thru UICollectionView class instances.So basicly you need an instance of UICollectionView, which
can be created programaticly or via Storyboard.
import UICollectionViewGallery
...
@IBOutlet weak var galleryCollectionView: UICollectionView!You can setup the basic UICollectionViewGallery with fallowing function and this propertis: GalleryFlowStyle which represents the enum for different styles, minLineSpacing represents space between cells, itemSize represents size of the cells, minScaleFactor represents scaling factor between the center cell and the rest of the visible cells.
galleryCollectionView.setGallery(withStyle: .autoDynamic, minLineSpacing: 10, itemSize: CGSize(width: 200, height: 200),minScaleFactor:0.6)Note that this general approuch sets up the same cell properties for both Vertical and Horizontal flow layouts,howover if you need a more custom approuch you can setup both flow layout seperatly thru the fallowing methods.
galleryCollectionView.setGallery(forLayout: .vertical, minLineSpacing: 10, itemSize: CGSize(width: 200, height:200), minScaleFactor: 0.5)
galleryCollectionView.setGallery(forLayout: .horizontal, minLineSpacing: 20, itemSize: CGSize(width: 300, height:300), minScaleFactor: 0.8)
galleryCollectionView.setGalleryWithCustomFlows(andStyle: .autoDynamic)You can disable infinite scroll and scaling by calling the fallowing function,they are enabled by default.
galleryCollectionView.setGaleryBehavior(forInfiniteScroll: false, andScalingElemnts: false)public enum GalleryFlowStyle {
case vertical // vertical flow
case horizontal // horizontal flow
case autoFixed // flow based on initial aspeciRatio eg. height > width = Vertical,
// heignt < width = Horizontal
case autoDynamic // auto flow based on dynamic aspect ratio: requares orientation change event to be catched
}For infinite scroll and .autoDynamic style support, you have to handle properly 2 events, and call the appropriate functions.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
galleryCollectionView.recenterIfNeeded()
} override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) {
galleryCollectionView.changeOrientation()
}You can find the indexPath for the center element by using the fallowing UICollectionView extension public property centerCellIndexPath
galleryCollectionView.centerCellIndexPathwhich retunrs an optional indexPath for the center element of the CollectionView
To run the example project, clone the repo, and run pod install from the Example directory first.
UICollectionViewGallery is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "UICollectionViewGallery"ro6lyo, [email protected]
UICollectionViewGallery is available under the MIT license. See the LICENSE file for more info.