ResizableCollectionView is a library to change the number of columns by pinch in / out.
github "chidori-app/ResizableCollectionView"
pod 'ResizableCollectionView'
- Download source code.
- Add ResizableCollectionView.swift to your project.
iOS 8.0 or higher.
- Add "Collection View" element to StoryBoard.
- Set the class of the element to
ResizableCollectionView
instead of CollectionView.
- If you install from Carthage, set the module of the element to
ResizableCollectionView
.
-
Set ResizableCollectionView's dataSource.
-
Implement ResizableCollectionViewDataSource. (ResizableCollectionViewDataSource extends UICollectionViewDataSource of which implementation is required.)
//MARK: - ResizableCollectionViewDataSource
extension ViewController: ResizableCollectionViewDataSource {
// optional
func minNumberOfCellsInLine(collectionView: ResizableCollectionView) -> Int {
return 2
}
// optional
func maxNumberOfCellsInLine(collectionView: ResizableCollectionView) -> Int {
return 6
}
func cellHeight(_ collectionView: ResizableCollectionView) -> CGFloat {
return CGFloat(50)
}
// optional
func marginOfCells(collectionView: ResizableCollectionView) -> CGFloat {
return CGFloat(5)
}
// optional
func thresholdOfZoom(collectionView: ResizableCollectionView) -> CGFloat {
return CGFloat(0.6)
}
// MARK: - UICollectionViewDataSource
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath)
}
}
ResizableCollectionView has four delegate methods.
func willPinchIn(collectionView: ResizableCollectionView)
func willPinchOut(collectionView: ResizableCollectionView)
func didPinchIn(collectionView: ResizableCollectionView)
func didPinchOut(collectionView: ResizableCollectionView)
See the DEMO project DEMO.xcodeproj
.
ResizableCollectionView was created by IOKA Masakazu in the development of Chidori
ResizableCollectionView is used in Chidori, iOS application.
Ask nscallop on Twitter (@nscallop)
The MIT License (MIT)
Copyright (c) 2016 IOKA
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.