Project 19 - CollectionView

DaY·2021년 5월 14일
1

iOS

목록 보기
44/52
post-thumbnail

CollectionLayout.swift

Collection View에 커스텀한 Layout을 삽입할 예정이다.
먼저, Delegate 프로토콜을 만들어준다.

protocol CollectionLayoutDelegate {
    func collectionView(_ collectionView: UICollectionView, heightForPhotoAtIndexPath indexPath: IndexPath, withWidth width: CGFloat) -> CGFloat
    
    func collectionView(_ collectionView: UICollectionView, heightForAnnotationAtIndexPath indexPath: IndexPath, withWidth width: CGFloat) -> CGFloat
}

CollectionViewLayout 클래스는 UICollectionViewLayoutAttributes를 상속한다.

새롭게 생성한 Layout을 사용하기 위해서는 Collection View의 Attributes Inspector에서 Layout을 Custom으로 설정하고 Class를 지정해주면 된다.

0개의 댓글