🍎 iOS/UI
[iOS/UI]UICollectionView header만들기(UICollectionReusableView)
Fomagran 💻
2019. 12. 26. 19:36
728x90
반응형
스토리보드에서 해당 콜렉션뷰에 CollectionReusableView를 추가해준 뒤
UICollectionReusableView 파일을 따로 만들어준다.


CollectionReusableView 클래스에 생성해준 파일 이름을 적고 identifier의 이름을 따로 생성해준다.


그리고 콜렉션뷰가 있는 클랙스에 아래 메소드를 추가해주면 끝!
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
//ofKind에 UICollectionView.elementKindSectionHeader로 헤더를 설정해주고
//withReuseIdentifier에 헤더뷰 identifier를 넣어주고
//생성한 헤더뷰로 캐스팅해준다.
let headerview = UICollectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "Typesomethingheader", for: indexPath) as! Collectionheader
return headerview
}
헤더를 설정해주면 스크롤 할 때 헤더와 같이 올라가게 된다!!

728x90
반응형