This implementation is built using a UICollectionView
and a custom flowLayout.
- iOS 11.0+
- Swift 5
Add Instructions to your Podfile:
pod 'VerticalFlowLayout'
Then, run the following command:
$ pod install
In Xcode, use File > Swift Packages > Add Package Dependency and use https://github.com/rastaman111/VerticalFlowLayout
.
To install with Carthage, simply add the following line to your Podfile:
github "rastaman111/VerticalFlowLayout"
If you prefer not to use any of dependency managers, you can integrate manually. Put Sources/VerticalFlowLayout
folder in your Xcode project. Make sure to enable Copy items if needed
and Create groups
.
To use VerticalFlowLayout
inside your UIViewController
:
import VerticalFlowLayout
class ViewController: UIViewController, VerticalCollectionViewDelegate, VerticalCollectionViewDataSource {
@IBOutlet var verticalView: VerticalView!
override func viewDidLoad() {
super.viewDidLoad()
verticalView.delegate = self
verticalView.datasource = self
// register cell
verticalView.register(nib: UINib(nibName: "ExampleCell", bundle: nil), forCellWithReuseIdentifier: "ExampleCell")
}
func cellForItemIn(verticalCollectionView: VerticalCollectionView, cellForItemAt indexPath: Int) -> UICollectionViewCell {
let cell = verticalCollectionView.dequeueReusableCell(withReuseIdentifier: "ExampleCell", for: indexPath) as! ExampleCell
return cell
}
func numberOfItemsIn(verticalCollectionView: VerticalCollectionView) -> Int {
return 20
}
func didSelectCell(verticalCollectionView: VerticalCollectionView, indexPath: Int) {
// Called when the user clicks on a cell.
}
}
The currently focussed cell index
verticalView.focussedCellIndex
Returns the visible cell object at the specified index.
verticalView.cellForItem(at index: Int) -> UICollectionViewCell?
Scrolls the collection view contents until the specified item is visible
verticalView.scrollToCell(at: Int, animated: Bool) -> Bool
Moves an item from one location to another in the collection view.
verticalView.moveCell(at: Int, to: Int)
Deletes cells at the specified indexes
verticalView.deleteCells(at: [Int])
Inserts new cells at the specified indexes
verticalView.insertCells(at: [Int])
VerticalFlowLayout is available under the MIT license. See the LICENSE file for more info.