Created
July 2, 2020 17:35
-
-
Save stevencurtis/d1ab6a6327250b5656ed01e27b841f63 to your computer and use it in GitHub Desktop.
quicklinkssection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct QuickLinksSection: LayoutSection { | |
func configureCell(collectionView: UICollectionView, indexPath: IndexPath, item: AnyHashable, position: Int) -> UICollectionViewCell { | |
guard let cell = collectionView.dequeueReusableCell( | |
withReuseIdentifier: String(describing: LinkCollectionViewCell.self), for: indexPath) as? LinkCollectionViewCell else { | |
fatalError("Unable to create new cell") } | |
if let item = item as? LinkDataModel { | |
cell.configure(with: item, final: position == 5) | |
} | |
return cell | |
} | |
func header(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionReusableView? { | |
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: TitleSupplementaryView.self), for: indexPath) | |
if let hdr = header as? TitleSupplementaryView { | |
hdr.configure(with: HeaderContent(title: "Quick Links", visibleButton: false, subtitle: "")) | |
hdr.titleButtonAction = { | |
print ("Clicked the following indexPath:", indexPath) | |
} | |
} | |
return header | |
} | |
var layoutSection: NSCollectionLayoutSection = { | |
let itemSize = NSCollectionLayoutSize( | |
widthDimension: .fractionalWidth(1.0), | |
heightDimension: .absolute(35)) | |
let item = NSCollectionLayoutItem(layoutSize: itemSize) | |
let groupSize = NSCollectionLayoutSize( | |
widthDimension: .fractionalWidth(1), | |
heightDimension: .absolute(35)) | |
let group = NSCollectionLayoutGroup.vertical( | |
layoutSize: groupSize, | |
subitem: item, | |
count: 1) | |
let headerSize = NSCollectionLayoutSize( | |
widthDimension: .fractionalWidth(1.0), | |
heightDimension: .estimated(22)) | |
let sectionHeader = NSCollectionLayoutBoundarySupplementaryItem( | |
layoutSize: headerSize, | |
elementKind: UICollectionView.elementKindSectionHeader, | |
alignment: .top) | |
let section = NSCollectionLayoutSection(group: group) | |
section.boundarySupplementaryItems = [sectionHeader] | |
return section | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment