👩🏻💻 오늘 공부한 내용
- CollectionReusableView 클래스
class WishListHeaderView: UICollectionReusableView{
@IBOutlet weak var titleLabel: UILabel!
func updateUI(_ title: String){
titleLabel.text = title
}
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return wishListViewModel.favoriteWishs().count
}
else {
return wishListViewModel.wishs.count
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section == 0 {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WishListCell", for: indexPath) as? WishListCell else {
return UICollectionViewCell()
}
return cell
}
else {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WishListCell", for: indexPath) as? WishListCell else {
return UICollectionViewCell()
}
return cell
}
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionView.elementKindSectionHeader:
guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "WishListHeaderView", for: indexPath) as? WishListHeaderView else {
return UICollectionReusableView()
}
if indexPath.section == 0{
header.updateUI("즐겨찾는 Wish")
}
else {
header.updateUI("나의 Wish")
}
return header
default:
return UICollectionReusableView ()
}
}
SystemImage로 설정
UIImage(systemName: "heart.fill")