리뷰 데이터가 있을때와 없을때 UI를 따로 처리해야하는 경우에 아래 코드처럼 분기 처리
func createReviewColumnSection() -> NSCollectionLayoutSection {
if viewModel?.isReviews == false {
// Item
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),heightDimension: .estimated(1))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),heightDimension: .estimated(1))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
// Section
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 16, leading: 20, bottom: 24, trailing: 20)
section.interGroupSpacing = 16
// Header
section.boundarySupplementaryItems = [
NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(41)), elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
]
// Background
let sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.background(elementKind: "GrayBackgroundViewInset")
section.decorationItems = [sectionBackgroundDecoration]
return section
} else {
// Item
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),heightDimension: .estimated(1))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),heightDimension: .estimated(1))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
// Section
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 16, leading: 20, bottom: 24, trailing: 20)
section.interGroupSpacing = 16
// Header
section.boundarySupplementaryItems = [
NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(41)), elementKind: UICollectionView.elementKindSectionHeader, alignment: .top),
NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(61)), elementKind: UICollectionView.elementKindSectionFooter, alignment: .bottom)
]
// Background
let sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.background(elementKind: "GrayBackgroundViewInset")
section.decorationItems = [sectionBackgroundDecoration]
return section
}
}
'iOS' 카테고리의 다른 글
| iOS - CollectionView Cell 뱃지 만들기 (1) | 2024.03.19 |
|---|---|
| iOS - 사파리 웹 인스펙터로 WebView 디버깅 하기 (0) | 2024.03.17 |
| collectionView - 가로방향으로 셀 3개 넣기 (0) | 2024.01.28 |
| iOS - 공유하기 기능 (0) | 2023.08.06 |
| iOS - StackView에서 Subview 제거할때 주의점 (0) | 2023.07.24 |