82 lines
2.6 KiB
Swift
82 lines
2.6 KiB
Swift
//
|
|
// ProgrammaticCollectionViewController.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 4/8/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/// A base view controller with a collection view.
|
|
@objc open class ProgrammaticCollectionViewController: ScrollingViewController {
|
|
|
|
public var collectionView: UICollectionView?
|
|
|
|
open override func loadView() {
|
|
let view = UIView()
|
|
view.backgroundColor = .white
|
|
|
|
let collection = createCollectionView()
|
|
view.addSubview(collection)
|
|
NSLayoutConstraint.constraintPinSubview(toSuperview: collection)
|
|
|
|
collectionView = collection
|
|
scrollView = collectionView
|
|
self.view = view
|
|
}
|
|
|
|
/// A place to register cells with the collectionView
|
|
open func registerCells() {}
|
|
|
|
open override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
registerCells()
|
|
}
|
|
|
|
/// Creates the layout for the collection.
|
|
open func createCollectionViewLayout() -> UICollectionViewLayout {
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.scrollDirection = .vertical
|
|
layout.minimumLineSpacing = 0
|
|
layout.minimumInteritemSpacing = 0
|
|
layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
|
|
return layout
|
|
}
|
|
|
|
/// Creates the collection view.
|
|
open func createCollectionView() -> UICollectionView {
|
|
let collection = UICollectionView(frame: .zero, collectionViewLayout: createCollectionViewLayout())
|
|
collection.translatesAutoresizingMaskIntoConstraints = false
|
|
collection.dataSource = self
|
|
collection.delegate = self
|
|
collection.showsHorizontalScrollIndicator = false
|
|
collection.backgroundColor = .white
|
|
collection.isAccessibilityElement = false
|
|
collection.contentInsetAdjustmentBehavior = .always
|
|
return collection
|
|
}
|
|
|
|
deinit {
|
|
collectionView?.delegate = nil
|
|
collectionView?.dataSource = nil
|
|
}
|
|
}
|
|
|
|
extension ProgrammaticCollectionViewController: UICollectionViewDataSource {
|
|
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return 0
|
|
}
|
|
|
|
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
return UICollectionViewCell()
|
|
}
|
|
|
|
open func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
return 1
|
|
}
|
|
}
|
|
|
|
extension ProgrammaticCollectionViewController: UICollectionViewDelegate {
|
|
}
|