UICollectionView
extension UICollectionView
-
Returns a UICollectionView with the specified layout.
Declaration
Swift
public convenience init(layout: UICollectionViewFlowLayout)
-
Registers a UICollectionViewCell for use in a UICollectionView.
By default, the class name of the cell is used as the reuse identifier.
Example:
class CustomCell: UICollectionViewCell {} let collectionView = UICollectionView() // registers the CustomCell class with a reuse identifier of "CustomCell" collectionView.registerCell(CustomCell)Declaration
Swift
public func registerCell<T>(_ type: T.Type, withIdentifier reuseIdentifier: String = String(describing: T.self)) where T : UICollectionViewCellParameters
typeThe type of cell to register.
reuseIdentifierThe reuse identifier for the cell (optional).
-
Dequeues a UICollectionViewCell for use in a UICollectionView.
By default, the class name of the cell is used as the reuse identifier.
Example:
class CustomCell: UICollectionViewCell {} let collectionView = UICollectionView() // dequeues a CustomCell class let cell = collectionView.dequeueReusableCell(CustomCell.self, forIndexPath: indexPath)Declaration
Swift
public func dequeueCell<T: UICollectionViewCell>(_ type: T.Type = T.self, withIdentifier reuseIdentifier: String = String(describing: T.self), for indexPath: IndexPath) -> TParameters
typeThe type of the cell.
indexPathThe index path at which to dequeue a new cell.
reuseIdentifierThe reuse identifier for the cell (optional).
Return Value
A force-casted UICollectionViewCell of the specified type.
-
Registers a UICollectionReusableView for use in a UICollectionView section header.
By default, the class name of the header view is used as the reuse identifier.
Example:
class CustomHeader: UICollectionReusableView {} let collectionView = UICollectionView() // registers the CustomCell class with a reuse identifier of "CustomHeader" collectionView.registerHeader(CustomHeader)Declaration
Swift
public func registerHeader<T>(_ type: T.Type, withIdentifier reuseIdentifier: String = String(describing: T.self)) where T : UICollectionReusableViewParameters
typeThe type of header view to register.
reuseIdentifierThe reuse identifier for the header view (optional).
-
Dequeues a UICollectionReusableView for use in a UICollectionView section header.
By default, the class name of the header view is used as the reuse identifier.
Example:
class CustomHeader: UICollectionReusableView {} let collectionView = UICollectionView() // dequeues a CustomHeader class let footerView = collectionView.dequeueReusableHeader(CustomHeader.self, forIndexPath: indexPath)Declaration
Swift
public func dequeueHeader<T: UICollectionReusableView>(_ type: T.Type = T.self, withIdentifier reuseIdentifier: String = String(describing: T.self), for indexPath: IndexPath) -> TParameters
typeThe type of the header view.
indexPathThe index path at which to dequeue a new header view.
reuseIdentifierThe reuse identifier for the header view (optional).
Return Value
A force-casted UICollectionReusableView of the specified type.
-
Registers a UICollectionReusableView for use in a UICollectionView section footer.
By default, the class name of the footer view is used as the reuse identifier.
Example:
class CustomFooter: UICollectionReusableView {} let collectionView = UICollectionView() // registers the CustomFooter class with a reuse identifier of "CustomFooter" collectionView.registerFooter(CustomFooter)Declaration
Swift
public func registerFooter<T>(_ type: T.Type, withIdentifier reuseIdentifier: String = String(describing: T.self)) where T : UICollectionReusableViewParameters
typeThe type of footer view to register.
reuseIdentifierThe reuse identifier for the footer view (optional).
-
Dequeues a UICollectionReusableView for use in a UICollectionView section footer.
By default, the class name of the footer view is used as the reuse identifier.
Example:
class CustomFooter: UICollectionReusableView {} let collectionView = UICollectionView() // dequeues a CustomFooter class let footerView = collectionView.dequeueReusableFooter(CustomFooter.self, forIndexPath: indexPath)Declaration
Swift
public func dequeueFooter<T: UICollectionReusableView>(_ type: T.Type = T.self, withIdentifier reuseIdentifier: String = String(describing: T.self), for indexPath: IndexPath) -> TParameters
typeThe type of the footer view.
indexPathThe index path at which to dequeue a new footer view.
reuseIdentifierThe reuse identifier for the footer view (optional).
Return Value
A force-casted UICollectionReusableView of the specified type.
-
Inserts rows into self.
Declaration
Swift
public func insert(_ indices: [Int], section: Int = 0, completion: @escaping (Bool) -> Void = { _ in })Parameters
indicesThe rows indices to insert into self.
sectionThe section in which to insert the rows (optional, defaults to 0).
completionThe completion handler, called after the rows have been inserted (optional).
-
Deletes rows from self.
Declaration
Swift
public func delete(_ indices: [Int], section: Int = 0, completion: @escaping (Bool) -> Void = { _ in })Parameters
indicesThe rows indices to delete from self.
sectionThe section in which to delete the rows (optional, defaults to 0).
completionThe completion handler, called after the rows have been deleted (optional).
-
Reloads rows in self.
Declaration
Swift
public func reload(_ indices: [Int], section: Int = 0, completion: @escaping (Bool) -> Void = { _ in })Parameters
indicesThe rows indices to reload in self.
sectionThe section in which to reload the rows (optional, defaults to 0).
completionThe completion handler, called after the rows have been reloaded (optional).
-
The minimum (
starting
)IndexPathfor traversing aUICollectionViewsequentially
.Declaration
Swift
public var minimumIndexPath: IndexPath { get } -
The maximum (
ending
)IndexPathfor traversing aUICollectionViewsequentially
.Declaration
Swift
public var maximumIndexPath: IndexPath { get } -
When
sequentially
traversing aUICollectionView, what’s the nextIndexPathafter the givenIndexPath.See also
var maximumIndexpathDeclaration
Swift
public func indexPath(after indexPath: IndexPath) -> IndexPath?Parameters
indexPathThe current indexPath; the path we want to find what comes after.
Return Value
The next indexPath, or nil if we’re at the maximumIndexPath
-
When
sequentially
traversing aUICollectionView, what’s the previousIndexPathbefore the givenIndexPath.See also
var minimumIndexPathDeclaration
Swift
public func indexPath(before indexPath: IndexPath) -> IndexPath?Parameters
indexPathThe current indexPath; the path we want to find what comes before.
Return Value
The prior indexPath, or nil if we’re at the minimumIndexPath
View on GitHub
Install in Dash
UICollectionView Extension Reference