collectionViewCell 사이에 공백없애기
✅ collectionViewCell 사이에 공백없애기
아래의 코드를 선언하면 저렇게 빈 공간이 생기게 된다.
var calendarList: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.register(CalendarCell.self, forCellWithReuseIdentifier: CalendarCell.identifier)
collectionView.isScrollEnabled = false
collectionView.backgroundColor = .red
return collectionView
}()
✅ 빈 공간을 없애려면?
var calendarList: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.minimumLineSpacing = 0 // 상하간격
layout.minimumInteritemSpacing = 0 // 좌우간격
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.register(CalendarCell.self, forCellWithReuseIdentifier: CalendarCell.identifier)
collectionView.isScrollEnabled = false
collectionView.backgroundColor = .red
return collectionView
}()
✅ 레이아웃
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// width는 무조건 7개 들어가야한다.
let widht = view.safeAreaLayoutGuide.layoutFrame.width / 7
let height = view.safeAreaLayoutGuide.layoutFrame.height / 5
return CGSize(width: widht, height: height)
}
✅ 그런데 다른 UI와 겹쳐보이면 안되니까 내 컬렉션 뷰의 높이만 이용하려먼?
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let widht = view.safeAreaLayoutGuide.layoutFrame.width / 7
let height = collectionView.frame.height / 5
// print(collectionView.frame.height)
return CGSize(width: widht, height: height)
}
'Archive > 위젯 캘린더(project-ios)' 카테고리의 다른 글
[iOS] UIButton SystemImage 크기 조절 (0) | 2022.05.04 |
---|---|
[iOS] UITableView BackgroundView didTapped ✨ (0) | 2022.05.04 |
[iOS] Swift Calendar 첫 날과 마지막 날 찾기 (0) | 2022.05.03 |
[iOS15] Device width, height in safeAreaLayoutGuide (0) | 2022.05.02 |