1234567891011121314151617181920212223242526272829303132333435363738394041 |
- //
- // CollectionViewUtil.swift
- // HCQuanfangtong
- //
- // Created by Apple on 2021/12/29.
- // Copyright © 2021 Jyp. All rights reserved.
- //
- import UIKit
- extension UICollectionView{
-
- func register<T>(withType type : T.Type) where T: UICollectionViewCell{
- self.register(UINib.loadNib(type), forCellWithReuseIdentifier: String(describing: type))
- }
- func registerClass<T>(withType type : T.Type) where T: UICollectionViewCell{
- self.register(type, forCellWithReuseIdentifier: String(describing: type))
- }
- func registerHeader<T>(withType type : T.Type) where T: UICollectionReusableView{
- self.register(UINib.loadNib(type), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: type))
- }
- func registerHeaderClass<T>(withType type : T.Type) where T: UICollectionReusableView{
- self.register(type, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: type))
- }
- func registerFooter<T>(withType type : T.Type) where T: UICollectionReusableView{
- self.register(UINib.loadNib(type), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: type))
- }
- func registerFooterClass<T>(withType type : T.Type) where T: UICollectionReusableView{
- self.register(type, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: type))
- }
- func dequeueReusableCell<T>(withType type : T.Type,for indexPath : IndexPath) -> T{
- return self.dequeueReusableCell(withReuseIdentifier: String(describing: type), for:indexPath) as! T
- }
-
- func dequeueReusableSupplementaryHeaderView<T>(withType type : T.Type,for indexPath : IndexPath) -> T{
- return self.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: type), for: indexPath) as! T
- }
- func dequeueReusableSupplementaryFooterView<T>(withType type : T.Type,for indexPath : IndexPath) -> T{
- return self.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: type), for: indexPath) as! T
- }
- }
|